Skip to content

Instantly share code, notes, and snippets.

View gkellogg's full-sized avatar

Gregg Kellogg gkellogg

View GitHub Profile
@gkellogg
gkellogg / rdfa_xmlliteral_serialization.rb
Created October 24, 2010 06:42
Code use to place XMLLiteral in canonical form and preserve @Profile, @Prefix, @vocab and @lang mappings.
# Add already mapped namespaces and language
@contents = contents.map do |c|
c = Nokogiri::XML.parse(c.copy(true).to_s) if c.is_a?(LibXML::XML::Node)
if c.is_a?(Nokogiri::XML::Element)
c = Nokogiri::XML.parse(c.dup.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS)).root
# Gather namespaces from self and decendant nodes
#
# prefix mappings
# Look for @xmlns and @prefix mappings. Add any other mappings from options[:prefixes]
# that aren't already defined on this node
@gkellogg
gkellogg / balhof-2011-02-18.rdf
Created February 18, 2011 17:52
Output from Ruby RDF::RDFXML version 0.3.2 serializer for sample OWL input
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns0="http://www.w3.org/2002/07/owl#" xmlns:ns1="http://example.org/" xmlns:ns2="http://www.w3.org/2000/01/rdf-schema#">
<ns0:AnnotationProperty rdf:about="http://example.org/describe_state"/>
<ns0:Class rdf:about="http://example.org/phenotype1">
<ns1:describe_state>
<ns1:state rdf:about="http://example.org/state1">
<ns2:label>leg has more than 10 and less than 30 setae</ns2:label>
</ns1:state>
</ns1:describe_state>
<ns0:equivalentClass>
@gkellogg
gkellogg / lee-list-1.rb
Created April 6, 2011 18:37
Original example
#!/usr/bin/env ruby
require 'rdf'
require 'rdf/n3'
doc = %q(
@prefix dms: <http://example.stanford.edu/ns/> .
@prefix ore: <http://www.openarchives.org/ore/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix item: <http://example.stanford.edu/item/> .
@gkellogg
gkellogg / Gemfile
Created February 11, 2012 02:17
A Micro Gem for running a simple SPARQL endpoint
source "http://rubygems.org"
gemspec
group :development do
gem 'shotgun'
gem "wirble"
end
@gkellogg
gkellogg / context.json
Created May 15, 2012 22:54
Yard JSON-LD example
{
"@context": {
"children": {"@id": "yard:children", "@type": "@id"},
"children": {"@id": "yard:children", "@type": "@id"},
"docstring": "yard:docstring",
"explicit": "yard:explicit",
"files": {"@id": "yard:files", "@type": "@id"},
"group": "yard:group",
"groups": "yard:groups",
"name": "yard:name",
@gkellogg
gkellogg / schema-heir.jsonld
Last active January 3, 2024 07:26
Schema.org class heirarchy in JSON-LD
{
"@context": {
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"schema": "http://schema.org/",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"rdfs:subClassOf": {
"@type": "@id"
},
"name": "rdfs:label",
"description": "rdfs:comment",
@gkellogg
gkellogg / giants.html
Last active August 29, 2015 13:57
YourSports entity description for SF Giants
<html>
<head>
{
"@context": [
"http://schema.org/",
"http://yoursports.com/vocab"
],
"@id": "http://yoursports.com/giants",
"@type": "SportsTeam",
"name": "San Francisco Giants",
@gkellogg
gkellogg / context.rb
Last active August 29, 2015 13:57
YourSports JSON-LD context and partial code for creating.
class Vocab
# Generate a JSON-LD context for the vocabulary + schema.org
module Context
# @return [Hash]
def generate_context
context = {
"@vocab" => "http://schema.org/",
"@language" => "en",
"foaf" => "http://xmlns.com/foaf/0.1/",
"hydra" => "http://www.w3.org/ns/hydra/core#",
@gkellogg
gkellogg / mongo_extensions.rb
Created September 12, 2014 09:51
Snippets for JSON-LD MongoDB adaptor
require 'bson'
module Wikia::Screen
# Extensions for mapping to/from BSON.
module MongoExtensions
def to_bson(obj)
obj = obj.dup
# Add created and modified dates
obj["schema:dateCreated"] = Time.parse(obj["schema:dateCreated"]) if obj.has_key?("schema:dateCreated")
@gkellogg
gkellogg / dct.jsonld
Created October 6, 2014 17:08
DCTerms context
{
"@context": {
"Agent": "http://purl.org/dc/terms/Agent",
"AgentClass": "http://purl.org/dc/terms/AgentClass",
"BibliographicResource": "http://purl.org/dc/terms/BibliographicResource",
"Box": "http://purl.org/dc/terms/Box",
"DCMIType": "http://purl.org/dc/terms/DCMIType",
"DDC": "http://purl.org/dc/terms/DDC",
"FileFormat": "http://purl.org/dc/terms/FileFormat",
"Frequency": "http://purl.org/dc/terms/Frequency",