Skip to content

Instantly share code, notes, and snippets.

@jpstroop

jpstroop/review.dot

Last active Aug 29, 2015
Embed
What would you like to do?
Blue Mountain Relationships in RDF experiments
// Command: dot -Tpng -o review.png review.dot
digraph G {
pad=".5";
label="\n\nReview / Work / Magazine Relationship Graph";
labelloc=bottom;
labeljust=left;
rankdir=LR
size="9"; // inches for the long side
fontpath="/usr/share/fonts";
graph [fontname="Monospace"];
node [fontname="Monospace"];
edge [fontname="Monospace"];
review [label="Hymen (review)\nAuthor: Marianne Moore", color=orange]
magazine [label="Broom 1923", color=green]
work [label="Hymen\nAuthor: Hilda Doolittle", color=blue]
review -> work [label="reviewOf"]
work -> review [label="reviews"]
review -> magazine [label="isPartOf"]
magazine -> review [label="hasPart"]
}
require 'linkeddata'
uris = {
bmtn: RDF::URI.new('http://bluemountain.org/orwhatever/'),
xsd: RDF::URI.new("http://www.w3.org/2001/XMLSchema#"),
rda: RDF::URI.new("http://rdvocab.info/RDARelationshipsWEMI/"),
naf: RDF::URI.new("http://id.loc.gov/authorities/names/"),
schema: RDF::URI.new("http://schema.org/"),
oclcschema: RDF::URI.new("http://purl.org/library/") # see http://experimental.worldcat.org/ontology/library.owl
}
prefixes = {
dc: RDF::DC.to_s,
bmtn: uris[:bmtn],
xsd: uris[:xsd],
rda: uris[:rda],
naf: uris[:naf],
schema: uris[:schema],
oclcschema: uris[:oclcschema]
}
g = RDF::Graph.new
magazine = RDF::URI.new(uris[:bmtn].join('broom'))
magazine_type = uris[:oclcschema].join("Periodical")
g << [magazine, RDF.type, magazine_type]
g << [magazine, RDF::DC.title, RDF::Literal.new("Broom", language: "en")]
g << [magazine, RDF::DC.issued, RDF::Literal.new(1923, datatype: RDF::XSD.gYear)]
poetry_book = RDF::URI.new(uris[:bmtn].join('doolittle-hymen'))
book_type = uris[:schema].join("Book")
doolittle = uris[:naf].join("n78095822")
g << [poetry_book, RDF.type, book_type]
g << [poetry_book, RDF::DC.title, RDF::Literal.new("Hymen", language: "en")]
g << [poetry_book, RDF::DC.creator, doolittle]
review = RDF::URI.new(uris[:bmtn].join('moore-hymen'))
review_type = uris[:schema].join("Review")
moore = uris[:naf].join("n50016866")
reviewOf_rel = uris[:rda].join('reviewOf')
g << [review, RDF.type, review_type]
g << [review, RDF::DC.isPartOf, magazine]
g << [review, RDF::DC.title, RDF::Literal.new("Hymen", language: "en")]
g << [review, RDF::DC.creator, moore]
g << [review, reviewOf_rel, poetry_book]
puts g.dump(:ttl, prefixes: prefixes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment