text:
require 'linkeddata'

graph = RDF::Graph.new
graph << [RDF::URI("http://www.museum.com/fish"),
          RDF.type,
          RDF::URI("http://www.cidoc-crm.org/cidoc-crm/E55_Type")]

unframed_json = JSON::LD::API::fromRdf(graph)

# Using this frame:
frame = {
  "@context"=> [
    "https://linked.art/ns/context/1/full.jsonld",
    {"crm" => "http://www.cidoc-crm.org/cidoc-crm/"}
  ]
}

# This works
puts JSON::LD::API.frame(unframed_json, frame, base: "http://www.example.com")

# But this doesn't.
begin
  puts JSON::LD::API.frame(unframed_json, frame)
rescue JSON::LD::JsonLdError::InvalidBaseIRI => e
  puts "This doesn't work: #{e}"
end

# But using this frame:
frame = {
  "@context"=> [
    {"crm" => "http://www.cidoc-crm.org/cidoc-crm/"}
  ]
}
# Both of these work
puts JSON::LD::API.frame(unframed_json, frame, base: "http://www.example.com")
puts JSON::LD::API.frame(unframed_json, frame)


text:
{
  "@context": {"@vocab": "http://example.org/"},
  "id": "person1",
  "type": "IdentityProfile",
  "credential": [{
    "@graph": {
      "id": "cred1",
      "claim": {
        "id": "person1",
        "ageOver": 21
      },
      "signature": { ... }
    }, {
    "@graph": {
      "id": "cred2",
      "claim": {
        "id": "person1",
        "passport": { ... },
      },
      "signature": { ... }
    }
  }]
}

repo_name: ruby-rdf/json-ld

repo_language: HTML

mime_type: text/plain


text:
<http://movies.example.org/StarWarsIV> <http://schema.org/name> "Star Wars IV" <http://movies.example.org/StarWarsIV> .
<http://movies.example.org/StarWarsIV> <http://schema.org/director> <http://people.example.org/Lucas> <http://movies.example.org/StarWarsIV> .
<http://movies.example.org/StarWarsIV> <http://schema.org/actor> <http://people.example.org/Ford> <http://movies.example.org/StarWarsIV> .
<http://movies.example.org/StarWarsIV> <http://schema.org/actor> <http://people.example.org/Alec> <http://movies.example.org/StarWarsIV> .
<http://people.example.org/HarrisonFord> <http://schema.org/name> "Harrison Ford" <http://people.example.org/HarrisonFord> .
<http://people.example.org/AlecGuinness> <http://schema.org/name> "Alec Guinness" <http://people.example.org/AlecGuinness> .
<http://people.example.org/AlecGuinness> <http://schema.org/birthDate> "1914-04-02"^^<http://www.w3.org/2001/XMLSchema#date> <http://people.example.org/AlecGuinness> .
<http://people.example.org/AlecGuinness> <http://schema.org/deathDate> "2000-08-05"^^<http://www.w3.org/2001/XMLSchema#date> <http://people.example.org/AlecGuinness> .
<http://people.example.org/GeorgeLucas> <http://schema.org/name> "George Lucas" <http://people.example.org/GeorgeLucas> .
<http://movies.example.org/StarWarsIV> <http://schema.org/relationships> <http://movies.example.org/StarWarsIV/Lucas> .
<http://movies.example.org/StarWarsIV> <http://schema.org/relationships> <http://movies.example.org/StarWarsIV/Ford> .
<http://movies.example.org/StarWarsIV> <http://schema.org/relationships> <http://movies.example.org/StarWarsIV/Alec> .
<http://movies.example.org/StarWarsIV/Lucas> <http://schema.org/source> <http://movies.example.org/StarWarsIV> .
<http://movies.example.org/StarWarsIV/Lucas> <http://schema.org/destination> <http://people.example.org/GeorgeLucas> .
<http://movies.example.org/StarWarsIV/Ford> <http://schema.org/source> <http://movies.example.org/StarWarsIV> .
<http://movies.example.org/StarWarsIV/Ford> <http://schema.org/destination> <http://people.example.org/HarrisonFord> .
<http://movies.example.org/StarWarsIV/Ford> <http://schema.org/asCharacter> "Han Solo" .
<http://movies.example.org/StarWarsIV/Alec> <http://schema.org/source> <http://movies.example.org/StarWarsIV> .
<http://movies.example.org/StarWarsIV/Alec> <http://schema.org/destination> <http://people.example.org/AlecGuinness> .
<http://movies.example.org/StarWarsIV/Alec> <http://schema.org/asCharacter> "Obi-Wan Kenobi" .


text:
@prefix dc: <http://purl.org/dc/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix senet: <https://senet.org/ns#> .

<https://senet.org/gm> a <http://vocab.org/frbr/core#Work>;
   dc:title "ãƒªã‚ºãƒ å¤©å›½"@ja,
     "Rhythm Paradise"@en;
   <https://senet.org/ns#unofficialTitle> "Rhythm Tengoku"@en;
   <https://senet.org/ns#urlkey> "rhythm-tengoku"^^xsd:string .


text:
require 'pp'
require 'linkeddata'

input = JSON.parse %({
  "@context": {
    "schema": "http://schema.org/",
    "name": "schema:name",
    "url": {"@id": "schema:url", "@type": "schema:URL"}
  },
  "name": "Jane Doe"
})

frame = JSON.parse %({
  "@context": {
    "schema": "http://schema.org/",
    "name": "schema:name",
    "url": { "@id": "schema:url", "@type": "schema:URL"}
  },
  "name": {},
  "url": {"@default": {"@value": "http://example.com", "@type": "schema:URL"}}
})

pp JSON::LD::API.frame(input, frame, logger: Logger.new(STDERR))


text:
#!/usr/bin/env ruby
require 'rubygems'
require 'rdf/rdfa'
require 'json/ld'

type_exclusion = %w(
FinancialService
ProfessionalService
EntertainmentBusiness
AnimalShelter
AutomotiveBusiness
Store
FoodEstablishment
HealthAndBeautyBusiness
LodgingBusiness
SportsActivityLocation
ChildCare
MedicalOrganization
DryCleaningOrLaundry
HomeAndConstructionBusiness
EmergencyService
EmploymentAgency
GovernmentOffice
InternetCafe
Library
RadioStation
RealEstateAgent
RecyclingCenter
SelfStorage
ShoppingCenter
TelevisionStation
TouristInformationCenter
)

context = JSON.parse(File.read(File.expand_path("../schema-context.jsonld", __FILE__)))['@context']
object_map = {}

# Extract IDs
ARGV.each do |infile|
  outfile = infile.sub('.html', '.jsonld')
  puts outfile
  RDF::Repository.load(infile) do |repo|
    JSON::LD::API.fromRdf(repo) do |expanded|
      JSON::LD::API.compact(expanded, context) do |compacted|
        compacted['@graph'].each do |obj|
          next if type_exclusion.include?(obj['name'])
          object_map[obj['@id']] = obj if obj['@type'] == "rdfs:Class"
        end
      end
    end
  end

  thing = object_map['schema:Thing']

  # Build type heirarchy
  object_map.each do |id, obj|
    Array(obj['rdfs:subClassOf']).each do |super_class|
      so = object_map[super_class]
      next if so.nil?
      raise "super class not found: #{super_class}" if so.nil?
      (so['children'] ||= []) << obj
    end
  end

  context = context.merge({"children" => {"@reverse" => "rdfs:subClassOf"}})
  context = {"@context" => context}
  File.open(outfile, 'w') do |f|
    f.puts context.merge(thing).to_json(JSON::LD::JSON_STATE)
  end
end