WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center
JSONLD (.jsonld)

Background

Import & Export

Import Elements

Options

Examples  
Basic Examples  
Applications  
See Also
GraphStore`

JSONLD (.jsonld)

Background

Import & Export

  • Import ["file.jsonld"] imports a JSON-LD file, returning an RDFStore .
  • Import ["file.jsonld",elements] imports the specified elements.
  • Export ["file.jsonld",expr] exports an RDFStore to a JSON-LD file.

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules" full list of rules for each element and option
    "Options" list of rules for options, properties and settings
  • Data representation elements:
  • "Data" an RDFStore
    "RawData" nested associations and lists
  • The "RawData" element is equivalent to the "RawJSON" format. The import result can be "compacted", "expanded", or "flattened" by specifying the "Profile" and "Context" import options.

Options

  • Import options:
  • "Base" Automatic base IRI used to resolve relative IRIs
    "DocumentLoader" Automatic function used to import remote contexts
    "ExpandContext" None context used to initialize the active context during expansion
    "ProduceGeneralizedRDF" False whether to import a file that contains a blank node in a property position
  • The value of "Base" is only used if the file does not specify a base IRI.
  • "Base" can take the following values:
  • Automatic the file name of the imported file
    None no base IRI
    "iri" or URL ["iri"] an IRI
  • An "ExpandContext" can be given to import a JSON file as an RDFStore .
  • Additional Import options for the "RawData" element:
  • "CompactArrays" True whether arrays of one element should be replaced with that element
    "Context" None context used for compaction
    "Profile" None how to represent data as JSONLD
  • Specifying the "CompactArrays", "Context" and "Profile" options during "RawData" import has the same effect as specifying those options during Export .
  • Export options:
  • "CompactArrays" True whether arrays of one element should be replaced with that element
    "Context" None context used for compaction
    "ExpandContext" None context used to initialize the active context during expansion
    "Profile" "Compacted" how to represent data as JSONLD
    "UseNativeTypes" False whether number and Boolean literals should be expressed as JSON numbers and Booleans
    "UseRDFType" False whether rdf:type predicates should be exported as rdf:type or @type
  • A "Context" is an association that specifies how short terms relate to IRIs, which datatypes values have and which classes IRIs belong to.
  • A "Profile" specifies how data is represented as JSONLD. Possible value include:
  • "Compacted" shorten IRIs to terms and compact IRIs, and values to numbers and string
    "Expanded" expand all terms and schort forms
    "Flattened" collect all properties of a node into a single JSON object and generate a label for each blank node

Examples

open all close all

Basic Examples  (1)

Wolfram Language code: Needs["GraphStore`"]

Import a document describing Albert Einstein:

Wolfram Language code: einsteinStore = ImportString["{ \"@context\":{ \"name\":\"http://xmlns.com/foaf/0.1/name\", \"birthDate\":{ \"@id\":\"http://schema.org/birthDate\", \"@type\":\"http://www.w3.org/2001/XMLSchema#date\" } }, \"@id\":\"http://www.wikidata.org/entity/Q937\", \"@type\":\"http://schema.org/Person\", \"name\":\"Albert Einstein\", \"birthDate\":\"1879年03月14日\" }", "JSONLD"]

Find the date of birth:

Wolfram Language code: einsteinStore//SPARQLSelect[RDFTriple[SPARQLVariable["person"], URL["http://schema.org/birthDate"], SPARQLVariable["birthDate"]]]

Export the same graph:

Wolfram Language code: ExportString[einsteinStore, "JSONLD"]

Specify a "context" to compact keys and values:

Wolfram Language code: ExportString[einsteinStore, "JSONLD", "Context" -> <| "name" -> "http://xmlns.com/foaf/0.1/name", "birthDate" -> <| "@id" -> "http://schema.org/birthDate", "@type" -> "http://www.w3.org/2001/XMLSchema#date" |> |>]

Applications  (1)

Wolfram Language code: Needs["GraphStore`"]

Import a Turtle document about the masses of various objects:

Wolfram Language code: massesStore = ImportString[" prefix qudt: <http://qudt.org/schema/qudt/> prefix unit: <http://qudt.org/vocab/unit/> prefix ex: <http://example.org/> ex:eifelTower ex:mass [qudt:numericValue 10100E0; qudt:unit unit:MetricTon] . ex:earth ex:mass [qudt:numericValue 5.97237E24; qudt:unit unit:Kilogram] . ex:caffeineMolecule ex:mass [qudt:numericValue 194.19E0; qudt:unit unit:UnifiedAtomicMassUnit] . ", "Turtle"]

Specify a context:

Wolfram Language code: massesContext = <| "mass" -> "http://example.org/mass", "value" -> "http://qudt.org/schema/qudt/numericValue", "unit" -> <| "@id" -> "http://qudt.org/schema/qudt/unit", "@type" -> "@id" |>, "qudt-unit" -> "http://qudt.org/vocab/unit/", "ex" -> "http://example.org/" |>;

Export the RDF graph as JSON-LD:

Wolfram Language code: ExportString[massesStore, "JSONLD", "UseNativeTypes" -> True, "Context" -> massesContext]

See Also

Formats: RawJSON   Turtle   TriG   RDFXML

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /