193 lines
5.6 KiB
Ruby
193 lines
5.6 KiB
Ruby
|
|
|
|
module LabMetadata
|
|
|
|
@@cnames = {}
|
|
|
|
def LabMetadata.build_people_metadata
|
|
members = $db["lab/members"]
|
|
|
|
members.each do |name, data|
|
|
data["link_relative"] = not(data.has_key? "link")
|
|
data["name"] = name
|
|
unless data.has_key? "shortname"
|
|
data["shortname"] =
|
|
name.
|
|
downcase.
|
|
gsub(/ /, "_").
|
|
gsub(/[^a-z0-9A-Z_]/, "")
|
|
end
|
|
@@cnames[name] = name
|
|
@@cnames[data["shortname"]] = name
|
|
@@cnames[data["ubit"]] = name if data.has_key? "ubit"
|
|
page = "/people/#{data["shortname"]}.html"
|
|
unless data.has_key? "link"
|
|
data["link"] = page
|
|
end
|
|
data["page"] = page
|
|
end
|
|
end
|
|
|
|
def LabMetadata.create_people_pages
|
|
known_pages =
|
|
GemSmith::all_outputs.
|
|
delete_if { |x| not /people\/.*\.html$/ =~ x }
|
|
|
|
$db["lab/members"].each do |name, data|
|
|
unless known_pages.include? data["page"]
|
|
GemSmith::add_file_string(data["page"], "#{name} hasn't written anything yet.")
|
|
end
|
|
GemSmith::metadata_for(data["page"]).merge!({
|
|
title: name,
|
|
name: name
|
|
}.merge(data))
|
|
end
|
|
end
|
|
|
|
def LabMetadata.data_for(person)
|
|
cname = @@cnames[person] || person
|
|
data = $db["lab/members"][cname]
|
|
if data.nil?
|
|
data = $db["people"][cname]
|
|
end
|
|
data
|
|
end
|
|
|
|
def LabMetadata.link_for(person)
|
|
cname = @@cnames[person] || person
|
|
data = $db["lab/members"][cname]
|
|
if data.nil? then person else "<a class=\"lab_member\" href=\"#{GemSmith::root_path(data["link"])}\">#{person}</a>" end
|
|
end
|
|
|
|
def LabMetadata.publications_for(person)
|
|
cname = @@cnames[person]
|
|
raise "Unknown person '#{person}'" if cname.nil?
|
|
$db["publications"].
|
|
where { |pub| pub["authors"].include? cname }
|
|
end
|
|
|
|
def LabMetadata.shortname_for(publication)
|
|
venue = LabMetadata.complete_venue(publication)
|
|
publication.fetch("shortname", [
|
|
publication["authors"][0].split(/ +/)[-1].downcase,
|
|
publication["year"],
|
|
publication["venue"].nil? ? nil : publication["venue"].downcase.gsub(/[^a-zA-Z0-9\-]/, ""),
|
|
publication["title"].split(/ +/).
|
|
map {|x| x.downcase.gsub(/[^a-zA-Z0-9\-]/, "") }.
|
|
delete_if {|x| ["the", "a"].include? x }[0]
|
|
].compact.join(":")
|
|
)
|
|
end
|
|
|
|
def LabMetadata.bibtex_for(publication)
|
|
venue = LabMetadata.complete_venue(publication)
|
|
authors = publication["authors"].
|
|
map { |author|
|
|
author = author.split(/ +/)
|
|
last = author.pop
|
|
"#{last}, #{author.join(" ")}"
|
|
}
|
|
|
|
type, meta =
|
|
case venue["type"]
|
|
when "workshop", "conference", "demo"
|
|
[ "inproceedings",
|
|
{
|
|
author: authors.join(" and "),
|
|
title: publication["title"],
|
|
booktitle: LabMetadata.venue_name(venue, size: :full),
|
|
year: publication["year"]
|
|
}
|
|
]
|
|
when "journal"
|
|
[ "article",
|
|
{
|
|
author: authors.join(" and "),
|
|
title: publication["title"],
|
|
journal: LabMetadata.venue_name(venue, size: :full),
|
|
volume: publication["volume"],
|
|
number: publication["number"],
|
|
year: publication["year"],
|
|
month: publication["month"],
|
|
pages: publication["pages"]
|
|
}
|
|
]
|
|
when "techreport"
|
|
[ "techreport",
|
|
{
|
|
author: authors.join(" and "),
|
|
title: publication["title"],
|
|
institution: LabMetadata.venue_name(venue, size: :full),
|
|
year: publication["year"]
|
|
}
|
|
]
|
|
when "patent"
|
|
[ "misc",
|
|
{
|
|
title: publication["title"],
|
|
author: publication["author"],
|
|
year: publication["year"]
|
|
}
|
|
]
|
|
else
|
|
raise "Unknown venue type '#{venue["type"]}' for publication '#{publication["title"]}'"
|
|
end
|
|
|
|
"@#{type}{#{LabMetadata.shortname_for(publication)},"+(
|
|
meta.delete_if { |k,v| v.nil? }.
|
|
map { |k,v| "\n #{k} = {#{v}}" }.
|
|
join(",")
|
|
)+"\n}"
|
|
end
|
|
|
|
def LabMetadata.members_on_project(project)
|
|
$db["lab/members"].values.
|
|
where { |m| m.fetch("projects", []).include? project }.
|
|
map { |m| m["name"] }
|
|
end
|
|
|
|
def LabMetadata.complete_venue(record)
|
|
v = record["venue"];
|
|
t = record["track"];
|
|
v = $db["venues"][v];
|
|
## if there is no additional metadata for the venue, we're done.
|
|
return record if v.nil?;
|
|
## if there's no request for a subtrack, merge with what we have.
|
|
return v.clone.merge record if t.nil?;
|
|
v = v["tracks"]
|
|
## if there's no additional metadata for any tracks, we're done
|
|
return record if v.nil?;
|
|
v = v[t]
|
|
## if there's no additional metadata for this specific track, we're done
|
|
return record if v.nil?;
|
|
## otherwise... merge with what we have
|
|
return v.clone.merge record
|
|
end
|
|
|
|
def LabMetadata.venue_name(record, args = {})
|
|
v = LabMetadata.complete_venue(record)
|
|
raise "Unknown venue: #{short}" if v.nil?
|
|
case args.fetch(:size, :full_parens)
|
|
when :full_parens then "#{v["fullname"]} (#{v["acronym"] || v["venue"]})"
|
|
when :full then v["fullname"]
|
|
when :short then short
|
|
end
|
|
end
|
|
|
|
def LabMetadata.abbreviate_person(name)
|
|
n = name.split(/ +/)
|
|
last = n.pop
|
|
(n.map { |n| "#{n[0]}." } + [last]).join(" ")
|
|
end
|
|
|
|
def LabMetadata.person_name(full, args = {})
|
|
person = LabMetadata.data_for(full)
|
|
person = {} if person.nil?
|
|
case args.fetch(:size, :short)
|
|
when :full then person["full"] or full
|
|
when :short then person["short"] or abbreviate_person(full)
|
|
when :last then person["last"] or full.split(/ +/).pop
|
|
end
|
|
end
|
|
|
|
end |