2016-05-25 12:06:00 -04:00
|
|
|
|
|
|
|
module LabMetadata
|
|
|
|
|
2016-06-14 19:56:33 -04:00
|
|
|
@@cnames = {}
|
|
|
|
|
2016-05-25 12:06:00 -04:00
|
|
|
def LabMetadata.build_people_metadata
|
2016-10-05 11:17:40 -04:00
|
|
|
members =
|
2016-05-25 12:06:00 -04:00
|
|
|
|
2016-10-05 11:17:40 -04:00
|
|
|
$db["lab/members"].each do |name, data|
|
2016-05-25 12:06:00 -04:00
|
|
|
data["link_relative"] = not(data.has_key? "link")
|
2016-05-25 16:58:50 -04:00
|
|
|
data["name"] = name
|
2016-06-14 19:56:33 -04:00
|
|
|
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"
|
2016-05-25 12:06:00 -04:00
|
|
|
unless data.has_key? "link"
|
2016-05-25 16:58:50 -04:00
|
|
|
data["link"] = page
|
2016-05-25 12:06:00 -04:00
|
|
|
end
|
2016-05-25 16:58:50 -04:00
|
|
|
data["page"] = page
|
2016-05-25 12:06:00 -04:00
|
|
|
end
|
2016-10-05 11:17:40 -04:00
|
|
|
|
|
|
|
$db["lab/alumni"].each do |name, data|
|
|
|
|
data["name"] = name
|
|
|
|
@@cnames[name] = name
|
|
|
|
@@cnames[data["shortname"]] = name
|
|
|
|
@@cnames[data["ubit"]] = name if data.has_key? "ubit"
|
|
|
|
end
|
2016-05-25 12:06:00 -04:00
|
|
|
end
|
|
|
|
|
2016-05-25 16:58:50 -04:00
|
|
|
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"]
|
2016-08-11 10:37:46 -04:00
|
|
|
GemSmith::add_file_string(data["page"], "#{name} hasn't written anything about themselves yet.")
|
2016-05-25 16:58:50 -04:00
|
|
|
end
|
|
|
|
GemSmith::metadata_for(data["page"]).merge!({
|
|
|
|
title: name,
|
|
|
|
name: name
|
|
|
|
}.merge(data))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-14 19:56:33 -04:00
|
|
|
def LabMetadata.data_for(person)
|
|
|
|
cname = @@cnames[person] || person
|
|
|
|
data = $db["lab/members"][cname]
|
|
|
|
if data.nil?
|
|
|
|
data = $db["people"][cname]
|
|
|
|
end
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2016-05-25 16:58:50 -04:00
|
|
|
def LabMetadata.link_for(person)
|
2016-06-14 19:56:33 -04:00
|
|
|
cname = @@cnames[person] || person
|
|
|
|
data = $db["lab/members"][cname]
|
2016-08-11 18:48:25 -04:00
|
|
|
unless data.nil? then
|
2016-08-10 11:32:33 -04:00
|
|
|
link =
|
|
|
|
if /^https?:\/\// =~ data["link"] then data["link"]
|
|
|
|
else GemSmith::root_path(data["link"]) end
|
|
|
|
"<a class=\"lab_member\" href=\"#{link}\">#{person}</a>"
|
2016-08-11 18:48:25 -04:00
|
|
|
else
|
|
|
|
alum = $db["lab/alumni/#{cname}"]
|
|
|
|
if alum and alum["link"] then
|
|
|
|
"<a class=\"lab_member\" href=\"#{alum["link"]}\">#{person}</a>"
|
|
|
|
elsif alum then
|
|
|
|
"<span class=\"lab_member\">#{person}</span>"
|
|
|
|
else
|
|
|
|
person
|
|
|
|
end
|
2016-08-10 11:32:33 -04:00
|
|
|
end
|
2016-05-25 16:58:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def LabMetadata.publications_for(person)
|
2016-06-14 19:56:33 -04:00
|
|
|
cname = @@cnames[person]
|
|
|
|
raise "Unknown person '#{person}'" if cname.nil?
|
2016-05-25 16:58:50 -04:00
|
|
|
$db["publications"].
|
2016-06-14 19:56:33 -04:00
|
|
|
where { |pub| pub["authors"].include? cname }
|
2016-05-25 16:58:50 -04:00
|
|
|
end
|
|
|
|
|
2016-06-17 22:42:59 -04:00
|
|
|
def LabMetadata.shortname_for(publication)
|
|
|
|
venue = LabMetadata.complete_venue(publication)
|
|
|
|
publication.fetch("shortname", [
|
|
|
|
publication["authors"][0].split(/ +/)[-1].downcase,
|
|
|
|
publication["year"],
|
2016-06-17 22:53:03 -04:00
|
|
|
publication["venue"].nil? ? nil : publication["venue"].downcase.gsub(/[^a-zA-Z0-9\-]/, ""),
|
2016-06-17 22:42:59 -04:00
|
|
|
publication["title"].split(/ +/).
|
2016-06-17 22:53:03 -04:00
|
|
|
map {|x| x.downcase.gsub(/[^a-zA-Z0-9\-]/, "") }.
|
2016-06-17 22:42:59 -04:00
|
|
|
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"],
|
2016-08-01 16:42:55 -04:00
|
|
|
booktitle: LabMetadata.venue_name(venue, size: :short),
|
2016-06-17 22:42:59 -04:00
|
|
|
year: publication["year"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
when "journal"
|
|
|
|
[ "article",
|
|
|
|
{
|
|
|
|
author: authors.join(" and "),
|
|
|
|
title: publication["title"],
|
2016-08-01 16:42:55 -04:00
|
|
|
journal: LabMetadata.venue_name(venue, size: :short),
|
2016-06-17 22:42:59 -04:00
|
|
|
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"],
|
2016-08-01 16:42:55 -04:00
|
|
|
institution: LabMetadata.venue_name(venue, size: :short),
|
2016-06-17 22:42:59 -04:00
|
|
|
year: publication["year"]
|
|
|
|
}
|
|
|
|
]
|
2016-12-24 13:05:58 -05:00
|
|
|
when "patent", "panel"
|
2016-06-17 22:42:59 -04:00
|
|
|
[ "misc",
|
|
|
|
{
|
|
|
|
title: publication["title"],
|
|
|
|
author: publication["author"],
|
|
|
|
year: publication["year"]
|
|
|
|
}
|
|
|
|
]
|
2016-08-11 18:40:41 -04:00
|
|
|
when "thesis"
|
|
|
|
[
|
|
|
|
"#{venue["degree"].downcase}thesis",
|
|
|
|
{
|
|
|
|
author: authors.join(" and "),
|
|
|
|
title: publication["title"],
|
|
|
|
school: venue["school"],
|
|
|
|
year: publication["year"]
|
|
|
|
}
|
|
|
|
]
|
2016-12-07 12:30:49 -05:00
|
|
|
when "abstract"
|
|
|
|
[ "misc",
|
|
|
|
{
|
|
|
|
author: authors.join(" and "),
|
|
|
|
title: publication["title"],
|
|
|
|
howpublished: LabMetadata.venue_name(venue, size: :short),
|
|
|
|
year: publication["year"]
|
|
|
|
}
|
|
|
|
]
|
2016-06-17 22:42:59 -04:00
|
|
|
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
|
|
|
|
|
2016-05-25 16:58:50 -04:00
|
|
|
def LabMetadata.members_on_project(project)
|
|
|
|
$db["lab/members"].values.
|
|
|
|
where { |m| m.fetch("projects", []).include? project }.
|
|
|
|
map { |m| m["name"] }
|
|
|
|
end
|
|
|
|
|
2016-10-05 11:17:40 -04:00
|
|
|
def LabMetadata.alumni_on_project(project)
|
|
|
|
$db["lab/alumni"].values.
|
|
|
|
where { |m| m.fetch("projects", []).include? project }.
|
|
|
|
map { |m| m["name"] }
|
|
|
|
end
|
|
|
|
|
2016-06-14 19:56:33 -04:00
|
|
|
def LabMetadata.complete_venue(record)
|
2016-06-17 22:42:59 -04:00
|
|
|
v = record["venue"];
|
|
|
|
t = record["track"];
|
2016-06-14 19:56:33 -04:00
|
|
|
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.
|
2016-06-17 22:42:59 -04:00
|
|
|
return v.clone.merge record if t.nil?;
|
2016-06-14 19:56:33 -04:00
|
|
|
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
|
2016-06-17 22:42:59 -04:00
|
|
|
return v.clone.merge record
|
2016-06-14 19:56:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def LabMetadata.venue_name(record, args = {})
|
|
|
|
v = LabMetadata.complete_venue(record)
|
2016-08-01 16:45:20 -04:00
|
|
|
short = v["acronym"] || v["venue"]
|
2016-06-14 19:56:33 -04:00
|
|
|
raise "Unknown venue: #{short}" if v.nil?
|
2016-08-01 16:45:20 -04:00
|
|
|
raise "Unknown abbreviation: #{v}" if short.nil?
|
2016-06-14 19:56:33 -04:00
|
|
|
case args.fetch(:size, :full_parens)
|
2016-08-01 16:45:20 -04:00
|
|
|
when :full_parens then "#{v["fullname"]} (#{short})"
|
2016-06-14 19:56:33 -04:00
|
|
|
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
|
|
|
|
|
2016-10-23 20:43:42 -04:00
|
|
|
@@publication_erb = File.open("lib/publication.erb"){ |f| ERB.new(f.readlines.join) }
|
|
|
|
|
|
|
|
def LabMetadata.render_pub(pub)
|
|
|
|
b = binding()
|
|
|
|
b.local_variable_set(:pub, pub)
|
|
|
|
@@publication_erb.result(b)
|
|
|
|
end
|
|
|
|
|
2016-05-25 12:06:00 -04:00
|
|
|
end
|