lib/bolognese/utils.rb in bolognese-1.6 vs lib/bolognese/utils.rb in bolognese-1.6.2
- old
+ new
@@ -1054,7 +1054,102 @@
linter = JsonLint::Linter.new
linter.send(:check_data, json, error_array)
error_array
end
+ def name_to_fos(name)
+ # first find subject in Fields of Science (OECD)
+ fos = JSON.load(File.read(File.expand_path('../../../resources/oecd/fos-mappings.json', __FILE__))).fetch("fosFields")
+
+ subject = fos.find { |l| l["fosLabel"] == name || "FOS: " + l["fosLabel"] == name }
+
+ if subject
+ return [{
+ "subject" => sanitize(name) },
+ {
+ "subject" => "FOS: " + subject["fosLabel"],
+ "subjectScheme" => "Fields of Science and Technology (FOS)",
+ "schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf"
+ }]
+ end
+
+ # if not found, look in Fields of Research (Australian and New Zealand Standard Research Classification)
+ # and map to Fields of Science. Add an extra entry for the latter
+ fores = JSON.load(File.read(File.expand_path('../../../resources/oecd/for-mappings.json', __FILE__)))
+ for_fields = fores.fetch("forFields")
+ for_disciplines = fores.fetch("forDisciplines")
+
+ subject = for_fields.find { |l| l["forLabel"] == name } ||
+ for_disciplines.find { |l| l["forLabel"] == name }
+
+ if subject
+ [{
+ "subject" => sanitize(name) },
+ {
+ "subject" => "FOS: " + subject["fosLabel"],
+ "subjectScheme" => "Fields of Science and Technology (FOS)",
+ "schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf"
+ }]
+ else
+ [{ "subject" => sanitize(name) }]
+ end
+ end
+
+ def hsh_to_fos(hsh)
+ # first find subject in Fields of Science (OECD)
+ fos = JSON.load(File.read(File.expand_path('../../../resources/oecd/fos-mappings.json', __FILE__))).fetch("fosFields")
+ subject = fos.find { |l| l["fosLabel"] == hsh["__content__"] || "FOS: " + l["fosLabel"] == hsh["__content__"] }
+
+ if subject
+ return [{
+ "subject" => sanitize(hsh["__content__"]),
+ "subjectScheme" => hsh["subjectScheme"],
+ "schemeUri" => hsh["schemeURI"],
+ "valueUri" => hsh["valueURI"],
+ "lang" => hsh["lang"] }.compact,
+ {
+ "subject" => "FOS: " + subject["fosLabel"],
+ "subjectScheme" => "Fields of Science and Technology (FOS)",
+ "schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf" }.compact]
+ end
+
+ # if not found, look in Fields of Research (Australian and New Zealand Standard Research Classification)
+ # and map to Fields of Science. Add an extra entry for the latter
+ fores = JSON.load(File.read(File.expand_path('../../../resources/oecd/for-mappings.json', __FILE__)))
+ for_fields = fores.fetch("forFields")
+ for_disciplines = fores.fetch("forDisciplines")
+
+ # try to extract forId
+ if hsh["subjectScheme"] == "FOR"
+ for_id = hsh["__content__"].split(" ").first
+ for_id = for_id.rjust(6, "0")
+
+ subject = for_fields.find { |l| l["forId"] == for_id } ||
+ for_disciplines.find { |l| l["forId"] == for_id[0..3] }
+ else
+ subject = for_fields.find { |l| l["forLabel"] == hsh["__content__"] } ||
+ for_disciplines.find { |l| l["forLabel"] == hsh["__content__"] }
+ end
+
+ if subject
+ [{
+ "subject" => sanitize(hsh["__content__"]),
+ "subjectScheme" => hsh["subjectScheme"],
+ "schemeUri" => hsh["schemeURI"],
+ "valueUri" => hsh["valueURI"],
+ "lang" => hsh["lang"] }.compact,
+ {
+ "subject" => "FOS: " + subject["fosLabel"],
+ "subjectScheme" => "Fields of Science and Technology (FOS)",
+ "schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf"
+ }]
+ else
+ [{
+ "subject" => sanitize(hsh["__content__"]),
+ "subjectScheme" => hsh["subjectScheme"],
+ "schemeUri" => hsh["schemeURI"],
+ "valueUri" => hsh["valueURI"],
+ "lang" => hsh["lang"] }.compact]
+ end
+ end
end
end