Package com.github.jsonldjava.core
Class Context
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<java.lang.String,java.lang.Object>
-
- com.github.jsonldjava.core.Context
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.String,java.lang.Object>
public class Context extends java.util.LinkedHashMap<java.lang.String,java.lang.Object>A helper class which still stores all the values in a map but gives member variables easily access certain keys- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description java.util.Map<java.lang.String,java.lang.Object>inverseprivate JsonLdOptionsoptionsprivate static longserialVersionUIDprivate java.util.Map<java.lang.String,java.lang.Object>termDefinitionsprivate static java.util.regex.PatternURL_PATTERN
-
Constructor Summary
Constructors Constructor Description Context()Context(JsonLdOptions opts)Context(java.lang.Object context, JsonLdOptions opts)Context(java.util.Map<java.lang.String,java.lang.Object> map)Context(java.util.Map<java.lang.String,java.lang.Object> map, JsonLdOptions opts)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String_iriCompactionStep5point4(java.lang.String iri, java.lang.Object value, java.lang.String compactIRI, java.lang.String candidate, java.util.Map<java.lang.String,java.lang.Object> termDefinitions)private voidcheckEmptyKey(java.util.Map<java.lang.String,java.lang.Object> map)Contextclone()(package private) java.lang.StringcompactIri(java.lang.String iri)(package private) java.lang.StringcompactIri(java.lang.String iri, boolean relativeToVocab)(package private) java.lang.StringcompactIri(java.lang.String iri, java.lang.Object value, boolean relativeToVocab, boolean reverse)IRI Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#iri-compaction Compacts an IRI or keyword into a term or prefix if it can be.java.lang.ObjectcompactValue(java.lang.String activeProperty, java.util.Map<java.lang.String,java.lang.Object> value)Value Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#value-compactionprivate voidcreateTermDefinition(java.util.Map<java.lang.String,java.lang.Object> context, java.lang.String term, java.util.Map<java.lang.String,java.lang.Boolean> defined)Create Term Definition Algorithm http://json-ld.org/spec/latest/json-ld-api/#create-term-definition(package private) java.lang.StringexpandIri(java.lang.String value, boolean relative, boolean vocab, java.util.Map<java.lang.String,java.lang.Object> context, java.util.Map<java.lang.String,java.lang.Boolean> defined)IRI Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#iri-expansionjava.lang.ObjectexpandValue(java.lang.String activeProperty, java.lang.Object value)java.lang.StringgetContainer(java.lang.String property)Retrieve container mapping.java.util.Map<java.lang.String,java.lang.Object>getInverse()Inverse Context Creation http://json-ld.org/spec/latest/json-ld-api/#inverse-context-creation Generates an inverse context for use in the compaction algorithm, if not already generated for the given active context.java.lang.StringgetLanguageMapping(java.lang.String property)java.util.Map<java.lang.String,java.lang.String>getPrefixes(boolean onlyCommonPrefixes)Return a map of potential RDF prefixes based on the JSON-LD Term Definitions in this context.(package private) java.util.Map<java.lang.String,java.lang.Object>getTermDefinition(java.lang.String key)java.lang.StringgetTypeMapping(java.lang.String property)private voidinit(JsonLdOptions options)java.lang.BooleanisReverseProperty(java.lang.String property)Contextparse(java.lang.Object localContext)Contextparse(java.lang.Object localContext, java.util.List<java.lang.String> remoteContexts)Context Processing Algorithm http://json-ld.org/spec/latest/json-ld-api/#context-processing-algorithmsprivate Contextparse(java.lang.Object localContext, java.util.List<java.lang.String> remoteContexts, boolean parsingARemoteContext)Helper method used to work around logic errors related to the recursive nature of the JSONLD-API Context Processing Algorithm.private java.lang.StringselectTerm(java.lang.String iri, java.util.List<java.lang.String> containers, java.lang.String typeLanguage, java.util.List<java.lang.String> preferredValues)Term Selection http://json-ld.org/spec/latest/json-ld-api/#term-selection This algorithm, invoked via the IRI Compaction algorithm, makes use of an active context's inverse context to find the term that is best used to compact an IRI.java.util.Map<java.lang.String,java.lang.Object>serialize()Deprecated.-
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
-
Methods inherited from class java.util.HashMap
compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
URL_PATTERN
private static final java.util.regex.Pattern URL_PATTERN
-
options
private JsonLdOptions options
-
termDefinitions
private java.util.Map<java.lang.String,java.lang.Object> termDefinitions
-
inverse
public java.util.Map<java.lang.String,java.lang.Object> inverse
-
-
Constructor Detail
-
Context
public Context()
-
Context
public Context(JsonLdOptions opts)
-
Context
public Context(java.util.Map<java.lang.String,java.lang.Object> map, JsonLdOptions opts)
-
Context
public Context(java.util.Map<java.lang.String,java.lang.Object> map)
-
Context
public Context(java.lang.Object context, JsonLdOptions opts)
-
-
Method Detail
-
init
private void init(JsonLdOptions options)
-
compactValue
public java.lang.Object compactValue(java.lang.String activeProperty, java.util.Map<java.lang.String,java.lang.Object> value)Value Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#value-compaction- Parameters:
activeProperty- The Active Propertyvalue- The value to compact- Returns:
- The compacted value
-
parse
public Context parse(java.lang.Object localContext, java.util.List<java.lang.String> remoteContexts) throws JsonLdError
Context Processing Algorithm http://json-ld.org/spec/latest/json-ld-api/#context-processing-algorithms- Parameters:
localContext- The Local Context object.remoteContexts- The list of Strings denoting the remote Context URLs.- Returns:
- The parsed and merged Context.
- Throws:
JsonLdError- If there is an error parsing the contexts.
-
parse
private Context parse(java.lang.Object localContext, java.util.List<java.lang.String> remoteContexts, boolean parsingARemoteContext) throws JsonLdError
Helper method used to work around logic errors related to the recursive nature of the JSONLD-API Context Processing Algorithm.- Parameters:
localContext- The Local Context object.remoteContexts- The list of Strings denoting the remote Context URLs.parsingARemoteContext- True if localContext represents a remote context that has been parsed and sent into this method and false otherwise. This must be set to know whether to propagate the @code key from the context to the result.- Returns:
- The parsed and merged Context.
- Throws:
JsonLdError- If there is an error parsing the contexts.
-
checkEmptyKey
private void checkEmptyKey(java.util.Map<java.lang.String,java.lang.Object> map)
-
parse
public Context parse(java.lang.Object localContext) throws JsonLdError
- Throws:
JsonLdError
-
createTermDefinition
private void createTermDefinition(java.util.Map<java.lang.String,java.lang.Object> context, java.lang.String term, java.util.Map<java.lang.String,java.lang.Boolean> defined) throws JsonLdErrorCreate Term Definition Algorithm http://json-ld.org/spec/latest/json-ld-api/#create-term-definition- Parameters:
context-defined-- Throws:
JsonLdError
-
expandIri
java.lang.String expandIri(java.lang.String value, boolean relative, boolean vocab, java.util.Map<java.lang.String,java.lang.Object> context, java.util.Map<java.lang.String,java.lang.Boolean> defined) throws JsonLdErrorIRI Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#iri-expansion- Parameters:
value-relative-vocab-context-defined-- Returns:
- Throws:
JsonLdError
-
compactIri
java.lang.String compactIri(java.lang.String iri, java.lang.Object value, boolean relativeToVocab, boolean reverse)IRI Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#iri-compaction Compacts an IRI or keyword into a term or prefix if it can be. If the IRI has an associated value it may be passed.- Parameters:
iri- the IRI to compact.value- the value to check or null.relativeToVocab- options for how to compact IRIs: vocab: true to split after @vocab, false not to.reverse- true if a reverse property is being compacted, false if not.- Returns:
- the compacted term, prefix, keyword alias, or the original IRI.
-
_iriCompactionStep5point4
public static java.lang.String _iriCompactionStep5point4(java.lang.String iri, java.lang.Object value, java.lang.String compactIRI, java.lang.String candidate, java.util.Map<java.lang.String,java.lang.Object> termDefinitions)
-
getPrefixes
public java.util.Map<java.lang.String,java.lang.String> getPrefixes(boolean onlyCommonPrefixes)
Return a map of potential RDF prefixes based on the JSON-LD Term Definitions in this context.No guarantees of the prefixes are given, beyond that it will not contain ":".
- Parameters:
onlyCommonPrefixes- Iftrue, the result will not include "not so useful" prefixes, such as "term1": "http://example.com/term1", e.g. all IRIs will end with "/" or "#". Iffalse, all potential prefixes are returned.- Returns:
- A map from prefix string to IRI string
-
compactIri
java.lang.String compactIri(java.lang.String iri, boolean relativeToVocab)
-
compactIri
java.lang.String compactIri(java.lang.String iri)
-
clone
public Context clone()
- Overrides:
clonein classjava.util.HashMap<java.lang.String,java.lang.Object>
-
getInverse
public java.util.Map<java.lang.String,java.lang.Object> getInverse()
Inverse Context Creation http://json-ld.org/spec/latest/json-ld-api/#inverse-context-creation Generates an inverse context for use in the compaction algorithm, if not already generated for the given active context.- Returns:
- the inverse context.
-
selectTerm
private java.lang.String selectTerm(java.lang.String iri, java.util.List<java.lang.String> containers, java.lang.String typeLanguage, java.util.List<java.lang.String> preferredValues)Term Selection http://json-ld.org/spec/latest/json-ld-api/#term-selection This algorithm, invoked via the IRI Compaction algorithm, makes use of an active context's inverse context to find the term that is best used to compact an IRI. Other information about a value associated with the IRI is given, including which container mappings and which type mapping or language mapping would be best used to express the value.- Returns:
- the selected term.
-
getContainer
public java.lang.String getContainer(java.lang.String property)
Retrieve container mapping.- Parameters:
property- The Property to get a container mapping for.- Returns:
- The container mapping if any, else null
-
isReverseProperty
public java.lang.Boolean isReverseProperty(java.lang.String property)
-
getTypeMapping
public java.lang.String getTypeMapping(java.lang.String property)
-
getLanguageMapping
public java.lang.String getLanguageMapping(java.lang.String property)
-
getTermDefinition
java.util.Map<java.lang.String,java.lang.Object> getTermDefinition(java.lang.String key)
-
expandValue
public java.lang.Object expandValue(java.lang.String activeProperty, java.lang.Object value) throws JsonLdError- Throws:
JsonLdError
-
serialize
@Deprecated public java.util.Map<java.lang.String,java.lang.Object> serialize()
Deprecated.
-
-