Package com.stardog.stark.io
Class ParserContext
- java.lang.Object
-
- com.stardog.stark.io.AbstractRDFHandler
-
- com.stardog.stark.io.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ParserContext.ParseError
-
Field Summary
Fields Modifier and Type Field Description static Option<java.lang.String>
BNODE_ID_PREFIX
The prefix that will be prepended to every bnode identifier be returned by the parser.boolean
caseInsensitiveDirectives
ParsedURI
mBaseIRI
long
mColumnNumber
Resource
mContext
long
mLineNumber
Current line number of the inputprotected com.stardog.stark.impl.NamespacesImpl
mNamespaces
Value
mObject
IRI
mPredicate
Resource
mSubject
-
Constructor Summary
Constructors Constructor Description ParserContext(RDFHandler theHandler, Options theOptions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BNode
createBNode()
Creates a new uniqueBNode
objectBNode
createBNode(java.lang.String theNodeID)
Creates aBNode
object for the specified identifier.Literal
createLiteral(java.lang.String label, java.lang.String lang, IRI datatype)
Creates aLiteral
object from parsed information and context.Statement
currentStatement()
void
end()
Notification that processing has finishedInvalidRDF
error(java.lang.String theMsg)
Indicates afatal error
void
error(java.lang.String theMsg, ParserContext.ParseError theError)
Indicates an error of the given typestatic 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.void
handle(Statement theStatement)
Event for when a statement was encounteredboolean
is(Option<java.lang.Boolean> theParserOption)
java.lang.String
namespace(java.lang.String thePrefix)
void
namespace(java.lang.String thePrefix, java.lang.String theIRI)
Event for when a namespace was encounteredvoid
reportStatement()
void
resetStatement()
IRI
resolveURI(java.lang.String theIRISpec)
Resolves a URI-string against the base URI and creates aIRI
object for it.void
start()
Notification that the processing has started
-
-
-
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
-
mSubject
public Resource mSubject
-
mPredicate
public IRI mPredicate
-
mObject
public Value mObject
-
mContext
public Resource mContext
-
mBaseIRI
public ParsedURI mBaseIRI
-
-
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 aIRI
object for it.- Throws:
InvalidRDF
-
is
public boolean is(Option<java.lang.Boolean> theParserOption)
-
start
public void start()
Description copied from class:AbstractRDFHandler
Notification that the processing has started- Specified by:
start
in interfaceRDFHandler
- Overrides:
start
in classAbstractRDFHandler
-
end
public void end()
Description copied from class:AbstractRDFHandler
Notification that processing has finished- Specified by:
end
in interfaceRDFHandler
- Overrides:
end
in classAbstractRDFHandler
-
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 interfaceRDFHandler
- Overrides:
namespace
in classAbstractRDFHandler
- Parameters:
thePrefix
- the namespace prefixtheIRI
- 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 afatal 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 messagetheError
- 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 aLiteral
object from parsed information and context.- Throws:
InvalidRDF
-
createBNode
public BNode createBNode(@Nonnull java.lang.String theNodeID)
Creates aBNode
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.
-
-