Class JsonLdApi
java.lang.Object
com.github.jsonldjava.core.JsonLdApi
A container object to maintain state relating to JsonLdOptions and the
current Context, and push these into the relevant algorithms in
JsonLdProcessor as necessary.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate class_____ _ _ _ _ _ _ | ___| __ __ _ _ __ ___ (_)_ __ __ _ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | '__/ _` | '_ ` _ \| | '_ \ / _` | / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _|| | | (_| | | | | | | | | | | (_| | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_| \__,_|_| |_| |_|_|_| |_|\__, | /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/ |___/private classprivate classprivate classHelper class for node usages -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intCounter specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifierBlank Node identifier map specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier(package private) Contextprivate final org.slf4j.Logger(package private) JsonLdOptions(package private) Object -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty JsonLdApi object using the default JsonLdOptions, and without initialization.JsonLdApi(JsonLdOptions opts) Constructs an empty JsonLdApi object using the given JsonLdOptions, and without initialization.JsonLdApi(Object input, JsonLdOptions opts) Constructs a JsonLdApi object using the given object as the initial JSON-LD object, and the given JsonLdOptions.JsonLdApi(Object input, Object context, JsonLdOptions opts) Constructs a JsonLdApi object using the given object as the initial JSON-LD object, the given context, and the given JsonLdOptions. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddFrameOutput(JsonLdApi.FramingContext state, Object parent, String property, Object output) Adds framing output to the given parent.Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithmCompaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithmprivate booleanExpansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithmExpansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithmprivate booleanfilterNode(JsonLdApi.FramingContext state, Map<String, Object> node, Map<String, Object> frame, boolean requireAll) filterNodes(JsonLdApi.FramingContext state, Map<String, Object> nodes, Map<String, Object> frame, boolean requireAll) private voidframe(JsonLdApi.FramingContext state, Map<String, Object> nodes, Map<String, Object> frame, Object parent, String property) Frames subjects according to the given frame.Performs JSON-LD framing.fromRDF(RDFDataset dataset) Converts RDF statements into JSON-LD.fromRDF(RDFDataset dataset, boolean noDuplicatesInDataset) Converts RDF statements into JSON-LD, presuming that there are no duplicates in the dataset.(package private) StringGenerates a fresh, unused, blank node identifier using the algorithm specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier(package private) StringGenerates a blank node identifier for the given key using the algorithm specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier(package private) voidgenerateNodeMap(Object element, Map<String, Object> nodeMap) _____ _ _ _ _ _ _ _ _ | ___| | __ _| |_| |_ ___ _ __ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | |/ _` | __| __/ _ \ '_ \ / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _| | | (_| | |_| || __/ | | | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_|\__,_|\__|\__\___|_| |_| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/(package private) void(package private) voidgenerateNodeMap(Object element, Map<String, Object> nodeMap, String activeGraph, Object activeSubject, String activeProperty, Map<String, Object> list) private JsonLdConsts.EmbedgetFrameEmbed(Map<String, Object> frame, JsonLdConsts.Embed thedefault) private BooleangetFrameFlag(Map<String, Object> frame, String name, boolean thedefault) private ObjectgetFrameValue(Map<String, Object> frame, String name) private voidinitialize(Object input, Object context) Initializes this object by cloning the input object usingJsonLdUtils.clone(Object), and by parsing the context usingContext.parse(Object).Performs RDF normalization on the given JSON-LD input.private static voidremoveDependents(Map<String, JsonLdApi.EmbedNode> embeds, String id) private static voidremoveEmbed(JsonLdApi.FramingContext state, String id) Removes an existing embed.toRDF()Adds RDF triples for each graph in the current node map to an RDF dataset.
-
Field Details
-
log
private final org.slf4j.Logger log -
opts
JsonLdOptions opts -
value
Object value -
context
Context context -
blankNodeIdentifierMap
-
blankNodeCounter
private int blankNodeCounterCounter specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier -
nodeMap
-
-
Constructor Details
-
JsonLdApi
public JsonLdApi()Constructs an empty JsonLdApi object using the default JsonLdOptions, and without initialization. -
JsonLdApi
Constructs a JsonLdApi object using the given object as the initial JSON-LD object, and the given JsonLdOptions.- Parameters:
input- The initial JSON-LD object.opts- The JsonLdOptions to use.- Throws:
JsonLdError- If there is an error initializing using the object and options.
-
JsonLdApi
Constructs a JsonLdApi object using the given object as the initial JSON-LD object, the given context, and the given JsonLdOptions.- Parameters:
input- The initial JSON-LD object.context- The initial context.opts- The JsonLdOptions to use.- Throws:
JsonLdError- If there is an error initializing using the object and options.
-
JsonLdApi
Constructs an empty JsonLdApi object using the given JsonLdOptions, and without initialization.
If the JsonLdOptions parameter is null, then the default options are used.- Parameters:
opts- The JsonLdOptions to use.
-
-
Method Details
-
initialize
Initializes this object by cloning the input object usingJsonLdUtils.clone(Object), and by parsing the context usingContext.parse(Object).- Parameters:
input- The initial object, which is to be cloned and used in operations.context- The context object, which is to be parsed and used in operations.- Throws:
JsonLdError- If there was an error cloning the object, or in parsing the context.
-
compact
public Object compact(Context activeCtx, String activeProperty, Object element, boolean compactArrays) throws JsonLdError Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm- Parameters:
activeCtx- The Active ContextactiveProperty- The Active Propertyelement- The current elementcompactArrays- True to compact arrays.- Returns:
- The compacted JSON-LD object.
- Throws:
JsonLdError- If there was an error during compaction.
-
compact
Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#compaction-algorithm- Parameters:
activeCtx- The Active ContextactiveProperty- The Active Propertyelement- The current element- Returns:
- The compacted JSON-LD object.
- Throws:
JsonLdError- If there was an error during compaction.
-
expand
Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm- Parameters:
activeCtx- The Active ContextactiveProperty- The Active Propertyelement- The current element- Returns:
- The expanded JSON-LD object.
- Throws:
JsonLdError- If there was an error during expansion.
-
expand
Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm- Parameters:
activeCtx- The Active Contextelement- The current element- Returns:
- The expanded JSON-LD object.
- Throws:
JsonLdError- If there was an error during expansion.
-
generateNodeMap
_____ _ _ _ _ _ _ _ _ | ___| | __ _| |_| |_ ___ _ __ / \ | | __ _ ___ _ __(_) |_| |__ _ __ ___ | |_ | |/ _` | __| __/ _ \ '_ \ / _ \ | |/ _` |/ _ \| '__| | __| '_ \| '_ ` _ \ | _| | | (_| | |_| || __/ | | | / ___ \| | (_| | (_) | | | | |_| | | | | | | | | |_| |_|\__,_|\__|\__\___|_| |_| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_| |___/- Throws:
JsonLdError
-
generateNodeMap
void generateNodeMap(Object element, Map<String, Object> nodeMap, String activeGraph) throws JsonLdError- Throws:
JsonLdError
-
generateNodeMap
-
generateBlankNodeIdentifier
Generates a blank node identifier for the given key using the algorithm specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier- Parameters:
id- The id, or null to generate a fresh, unused, blank node identifier.- Returns:
- A blank node identifier based on id if it was not null, or a fresh, unused, blank node identifier if it was null.
-
generateBlankNodeIdentifier
String generateBlankNodeIdentifier()Generates a fresh, unused, blank node identifier using the algorithm specified in: http://www.w3.org/TR/json-ld-api/#generate-blank-node-identifier- Returns:
- A fresh, unused, blank node identifier.
-
frame
Performs JSON-LD framing.- Parameters:
input- the expanded JSON-LD to frame.frame- the expanded JSON-LD frame to use.- Returns:
- the framed output.
- Throws:
JsonLdError- If the framing was not successful.
-
createsCircularReference
-
frame
private void frame(JsonLdApi.FramingContext state, Map<String, Object> nodes, Map<String, throws JsonLdErrorObject> frame, Object parent, String property) Frames subjects according to the given frame.- Parameters:
state- the current framing state.frame- the frame.parent- the parent subject or top-level array.property- the parent property, initialized to null.- Throws:
JsonLdError- If there was an error during framing.
-
getFrameValue
-
getFrameFlag
-
getFrameEmbed
private JsonLdConsts.Embed getFrameEmbed(Map<String, Object> frame, JsonLdConsts.Embed thedefault) throws JsonLdError- Throws:
JsonLdError
-
removeEmbed
Removes an existing embed.- Parameters:
state- the current framing state.id- the @id of the embed to remove.
-
removeDependents
-
filterNodes
private Map<String,Object> filterNodes(JsonLdApi.FramingContext state, Map<String, Object> nodes, Map<String, throws JsonLdErrorObject> frame, boolean requireAll) - Throws:
JsonLdError
-
filterNode
private boolean filterNode(JsonLdApi.FramingContext state, Map<String, Object> node, Map<String, throws JsonLdErrorObject> frame, boolean requireAll) - Throws:
JsonLdError
-
addFrameOutput
private static void addFrameOutput(JsonLdApi.FramingContext state, Object parent, String property, Object output) Adds framing output to the given parent.- Parameters:
state- the current framing state.parent- the parent to add to.property- the parent property.output- the output to add.
-
fromRDF
Converts RDF statements into JSON-LD.- Parameters:
dataset- the RDF statements.- Returns:
- A list of JSON-LD objects found in the given dataset.
- Throws:
JsonLdError- If there was an error during conversion from RDF to JSON-LD.
-
fromRDF
Converts RDF statements into JSON-LD, presuming that there are no duplicates in the dataset.- Parameters:
dataset- the RDF statements.noDuplicatesInDataset- True if there are no duplicates in the dataset and false otherwise.- Returns:
- A list of JSON-LD objects found in the given dataset.
- Throws:
JsonLdError- If there was an error during conversion from RDF to JSON-LD.
-
toRDF
Adds RDF triples for each graph in the current node map to an RDF dataset.- Returns:
- the RDF dataset.
- Throws:
JsonLdError- If there was an error converting from JSON-LD to RDF.
-
normalize
Performs RDF normalization on the given JSON-LD input.- Parameters:
dataset- the expanded JSON-LD object to normalize.- Returns:
- The normalized JSON-LD object
- Throws:
JsonLdError- If there was an error while normalizing.
-