Module:Index

Revision as of 05:41, 3 February 2023 by Editor (talk | contribs) (Created page with "local getArgs = require('Module:Arguments').getArgs; local defArgs = require('Module:Arguments').defaultArgs; local index = {}; function index.Author( frame ) local args = defArgs(getArgs(frame), 1, ""); local arg = args[1]; local key = arg:match("%w+"); local H = {}; local I = {}; for line in arg:gmatch("(%S+)") do for names, ja, yr in string.gmatch(line,"([%a:_']+),([%w\._]+),([%d]+),") do for name in string.gmatch(names,"([%a_']+)") do if (st...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Index/doc

local getArgs = require('Module:Arguments').getArgs;
local defArgs = require('Module:Arguments').defaultArgs;
local index = {};

function index.Author( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  local key = arg:match("%w+");
  local H = {};
  local I = {};
  for line in arg:gmatch("(%S+)") do
  for names, ja, yr in string.gmatch(line,"([%a:_']+),([%w\._]+),([%d]+),") do
    for name in string.gmatch(names,"([%a_']+)") do
      if (string.sub(name,0,1) == key) then
        if (H[name] == nil) then
          tmp = {};
          tmp[line] = tonumber(yr);
          H[name] = tmp;
          table.insert(I, name);
        else
          tmp = H[name];
          tmp[line] = tonumber(yr);
        end
      end
    end
  end
  end
  table.sort(I);
  local ret = "";
  for i=1,table.getn(I) do
    local author = I[i];
    local tmp = H[author];
    local count = 0;
    local peakDist = {};
    local coAu = {};
    local earliest = 3000;
    local latest = 0;
    for k,v in pairs(tmp) do
      --check earliest and latest publications
      if (earliest > v) then earliest = v; end
      if (latest < v) then latest = v; end
      count = count + 1;
      for i=v-2,v+2 do
        if (peakDist[i] == nil) 
          then peakDist[i] = 3-math.abs(v-i);
          else peakDist[i] = peakDist[i] + 3-math.abs(v-i);
        end
      end
      --check major coauthors
      for names, ja, yr in string.gmatch(k,"([%a:_']+),([%w\._]+),([%d]+),") do
        for name in string.gmatch(names,"([%a_']+)") do
          if (name ~= author) then 
            if (coAu[name] == nil) then
              coAu[name] = 1;
            else
              coAu[name] = coAu[name] + 1;
            end
          end
        end
      end 
    end
    local peak = 0;
    local peakY = 0;
    for k,v in pairs(peakDist) do
      if (v > peak) then peakY = k; peak = v; end
    end
    local auL = "";
    if (count > 4) then
      for k,v in pairs(coAu) do
        if (v >= 3) then 
          if (auL == "") then
            auL = k; else auL = auL .. ":" .. k; end
        end
      end
    end
    ret = ret .. "&&" .. author .. 
"&&" .. count .. "&&" .. earliest .. "&&" .. latest ..
"&&" .. peakY .. "&&" .. auL .. "\n";
  end
  return ret;
end

function index.FormulaFunc1( frame )
  local args = defArgs(getArgs(frame), 4, "", "", "", "");
  local arg = args[1];
  local arg1 = args[2];
  local arg2 = tonumber(args[3])-1;
  local arg4 = args[4];

  local output = "";
  for id in arg:gmatch("&&(%w+)") do
    output = output.."%formula%" .. arg1 .. "%" .. arg2 .. "%Index/formula%"..id.."%" .. arg4;
  end
  return output;
end

function index.FormulaFunc2( frame )
  local args = defArgs(getArgs(frame), 4, "", "", "", "");
  local arg = args[1];
  local arg1 = args[2];
  local arg2 = tonumber(args[3])+1;
  local arg4 = args[4];

  local id;
  local output = "";
  for id in arg:gmatch("&&(%w+)") do
    output = output.."%formula%" .. arg1 .. "%" .. arg2 .. "%Index/formula%"..id.."%" .. arg4;
  end
  return output;
end

function index.FormulaIndexTable( frame )
  local args = defArgs(getArgs(frame), 3, "", "C", "20");
  local arg = args[1];
  local arg1 = args[2];
  local arg2 = args[3];

  local id, formula;
  local pat = arg1 .. arg2;
  local hash = {};
  local idx = {};
  for id, formula in arg:gmatch("&&(%w+)&&([%a%d]+)") do
    if (formula.match(formula, pat) ~= null) then
      if (hash[formula] == null)
        then hash[formula] = id;
          table.insert(idx, formula);
        else hash[formula] = hash[formula].."&&"..id;
      end
    end
  end
  table.sort(idx);
  local output = "";
  for id, val in pairs(idx) do
    output = output .. val .."&&".. hash[val] .. "\n";
  end
  return output;
end

function index.MassIndexTable( frame )
  local args = defArgs(getArgs(frame), 3, "", "0", "2000");
  local arg = args[1];
  local arg1 = args[2];
  local arg2 = args[3];

  local id, ms, msd;
  local min = arg1;
  local max = arg2;
  local hash = {};
  local idx = {};
  for id, ms in arg:gmatch("&&(%w+)&&([%d\.]+)") do
    msd = tonumber(ms); ---質量の最小と最大の間に入る部分のみ考慮
    if ((msd >= min) and (msd <= max)) then
      if (hash[msd] == null)
        then hash[msd] = id;
          table.insert(idx, msd);
        else hash[msd] = hash[msd].."&&"..id;
      end
    end
  end
  table.sort(idx);
  local output = "";
  for id, val in pairs(idx) do
    output = output .. val .."&&".. hash[val] .. "\n";
  end
  return output;
end

function index.Name( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  local key = arg:match("%w+");
  local H = {};
  local I = {};
  for id, name in arg:gmatch("&&(%w+).Common Name=&&(%S+)") do
    name = string.lower(name);
    for term in string.gmatch(name,"(%a+)") do
      if ((string.len(term) > 3) and
          (string.sub(term,0,1) == key)) then
        if (H[term] == nil) then
          H[term] = id; table.insert(I, term);
        else
          H[term] = H[term] .. ";" .. id;
        end
      end
    end
  end
  table.sort(I);
  local ret = "";
  for i=1,table.getn(I) do
    local k = I[i];
    ret = ret .. "* '''" .. k;
    for id in string.gmatch(H[k],"%w+") do
      ret = ret .. "'''&nbsp;&nbsp; [[" .. id .."]] &nbsp; ";
    end
    ret = ret .. "\n";
  end
  return ret;
end

return index