Class ParserContext

  • All Implemented Interfaces:
    RDFHandler
    Direct Known Subclasses:
    IOParserContext

    public class ParserContext
    extends AbstractRDFHandler

    Object to hold the current state of the parsing operation, parsing configuration, and Value creation.

    This class can and should be extended by each specific parser to add additional state and functionality for parsing their supported format.

    Since:
    1.0
    Version:
    1.0
    Author:
    Michael Grove
    • Field Detail

      • BNODE_ID_PREFIX

        public static final Option<java.lang.String> BNODE_ID_PREFIX
        The prefix that will be prepended to every bnode identifier be returned by the parser. For internal use only.
      • caseInsensitiveDirectives

        public final boolean caseInsensitiveDirectives
      • mNamespaces

        protected final com.stardog.stark.impl.NamespacesImpl mNamespaces
      • mLineNumber

        public long mLineNumber
        Current line number of the input
      • mColumnNumber

        public long mColumnNumber
      • mPredicate

        public IRI mPredicate
      • mObject

        public Value mObject
    • Constructor Detail

      • ParserContext

        public ParserContext​(@Nonnull
                             RDFHandler theHandler,
                             @Nonnull
                             Options theOptions)
    • Method Detail

      • resolveURI

        @Nonnull
        public IRI resolveURI​(@Nonnull
                              java.lang.String theIRISpec)
                       throws InvalidRDF
        Resolves a URI-string against the base URI and creates a IRI object for it.
        Throws:
        InvalidRDF
      • is

        public boolean is​(Option<java.lang.Boolean> theParserOption)
      • handle

        public void handle​(@Nonnull
                           Statement theStatement)
        Event for when a statement was encountered
        Parameters:
        theStatement - the statement
      • namespace

        public void namespace​(@Nonnull
                              java.lang.String thePrefix,
                              @Nonnull
                              java.lang.String theIRI)
        Event for when a namespace was encountered
        Specified by:
        namespace in interface RDFHandler
        Overrides:
        namespace in class AbstractRDFHandler
        Parameters:
        thePrefix - the namespace prefix
        theIRI - the associated IRI
      • namespace

        @Nonnull
        public java.lang.String namespace​(@Nonnull
                                          java.lang.String thePrefix)
      • currentStatement

        public Statement currentStatement()
      • reportStatement

        public void reportStatement()
      • resetStatement

        public void resetStatement()
      • error

        public InvalidRDF error​(java.lang.String theMsg)
        Indicates a fatal error
        Parameters:
        theMsg - the error message
        Returns:
        this will always raise an exception
      • error

        public void error​(java.lang.String theMsg,
                          ParserContext.ParseError theError)
        Indicates an error of the given type
        Parameters:
        theMsg - the error message
        theError - the type of the error
      • createLiteral

        public Literal createLiteral​(@Nonnull
                                     java.lang.String label,
                                     @Nullable
                                     java.lang.String lang,
                                     @Nullable
                                     IRI datatype)
                              throws InvalidRDF
        Creates a Literal object from parsed information and context.
        Throws:
        InvalidRDF
      • createBNode

        public BNode createBNode()
        Creates a new unique BNode object
      • createBNode

        public BNode createBNode​(@Nonnull
                                 java.lang.String theNodeID)
        Creates a BNode object for the specified identifier.
      • getRandomBnodeIdPrefix

        public static java.lang.String getRandomBnodeIdPrefix()
        Returns a new randomly generated string to be used as the prefix for bnode identifiers that will be returned by the parser. It is important that each parsr instance uses a unique prefix or otherwise parsed from different files can be mapped to the same RDF node.