Class Context

All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>, SequencedMap<String,Object>

public class Context extends LinkedHashMap<String,Object>
A helper class which still stores all the values in a map but gives member variables easily access certain keys
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • init

      private void init(JsonLdOptions options)
    • compactValue

      public Object compactValue(String activeProperty, Map<String,Object> value)
      Value Compaction Algorithm http://json-ld.org/spec/latest/json-ld-api/#value-compaction
      Parameters:
      activeProperty - The Active Property
      value - The value to compact
      Returns:
      The compacted value
    • parse

      public Context parse(Object localContext, List<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(Object localContext, List<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(Map<String,Object> map)
    • parse

      public Context parse(Object localContext) throws JsonLdError
      Throws:
      JsonLdError
    • createTermDefinition

      private void createTermDefinition(Map<String,Object> context, String term, Map<String,Boolean> defined) throws JsonLdError
      Create Term Definition Algorithm http://json-ld.org/spec/latest/json-ld-api/#create-term-definition
      Parameters:
      context -
      defined -
      Throws:
      JsonLdError
    • expandIri

      String expandIri(String value, boolean relative, boolean vocab, Map<String,Object> context, Map<String,Boolean> defined) throws JsonLdError
      IRI Expansion Algorithm http://json-ld.org/spec/latest/json-ld-api/#iri-expansion
      Parameters:
      value -
      relative -
      vocab -
      context -
      defined -
      Returns:
      Throws:
      JsonLdError
    • compactIri

      String compactIri(String iri, 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 String _iriCompactionStep5point4(String iri, Object value, String compactIRI, String candidate, Map<String,Object> termDefinitions)
    • getPrefixes

      public Map<String,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 - If true, the result will not include "not so useful" prefixes, such as "term1": "http://example.com/term1", e.g. all IRIs will end with "/" or "#". If false, all potential prefixes are returned.
      Returns:
      A map from prefix string to IRI string
    • compactIri

      String compactIri(String iri, boolean relativeToVocab)
    • compactIri

      String compactIri(String iri)
    • clone

      public Context clone()
      Overrides:
      clone in class HashMap<String,Object>
    • getInverse

      public Map<String,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 String selectTerm(String iri, List<String> containers, String typeLanguage, List<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 String getContainer(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 Boolean isReverseProperty(String property)
    • getTypeMapping

      public String getTypeMapping(String property)
    • getLanguageMapping

      public String getLanguageMapping(String property)
    • getTermDefinition

      Map<String,Object> getTermDefinition(String key)
    • expandValue

      public Object expandValue(String activeProperty, Object value) throws JsonLdError
      Throws:
      JsonLdError
    • serialize

      @Deprecated public Map<String,Object> serialize()
      Deprecated.