Class StringParser
Static Helper Class which allows raw strings of RDF/SPARQL Results to be parsed directly.
Inherited Members
Namespace: VDS.RDF.Parsing
Assembly: dotNetRdf.dll
Syntax
public static class StringParser
Remarks
The API structure for dotNetRDF means that our IRdfReader classes which are our Parsers only have to support parsing from a file or a stream. For most applications this is fine but there may be occassions when you wish to parse a small fragment of RDF and you don't want to have to put it into a file before you can parse it.
Methods
| Edit this page View SourceGetDatasetParser(string)
Uses the format detection rules to determine the most likely RDF Dataset Parser.
Declaration
public static IStoreReader GetDatasetParser(string data)
Parameters
Type | Name | Description |
---|---|---|
string | data | Raw RDF Dataset String. |
Returns
Type | Description |
---|---|
IStoreReader |
GetParser(string)
Uses the rules described in the remarks for the Parse() to return the most likely Parser.
Declaration
public static IRdfReader GetParser(string data)
Parameters
Type | Name | Description |
---|---|---|
string | data | Raw RDF String. |
Returns
Type | Description |
---|---|
IRdfReader |
GetResultSetParser(string)
Uses the format detection rules to return the most likely SPARQL Results parser.
Declaration
public static ISparqlResultsReader GetResultSetParser(string data)
Parameters
Type | Name | Description |
---|---|---|
string | data | Raw SPARQL Results String. |
Returns
Type | Description |
---|---|
ISparqlResultsReader |
Parse(IGraph, string)
Parses a raw RDF String (attempts to auto-detect the format).
Declaration
public static void Parse(IGraph g, string data)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to load into. |
string | data | Raw RDF String. |
Remarks
Auto-detection is based on testing the string to see if it contains certain keyword constructs which might indicate a particular syntax has been used. This detection may not always be accurate and it may choose a parser which is less expressive than the actual syntax e.g. TurtleParser instead of Notation3Parser as it tends to guess downwards.
For example if you parsed a Notation 3 string that contained Graph Literals but didn't use any of the Notation 3 specific directives like @keywords it would be assumed to be Turtle but then would fail to parse
The auto-detection rules used are as follows:
- If it contains <?xml and <rdf:RDF then it's most likely RDF/XML
- If it contains <html then it's most likely HTML with possibly RDFa embedded
-
If it contains @prefix or @base then its Turtle/Notation 3
- If it contains @keywords, @forall or @forsome then it's Notation 3
- Otherwise it's Turtle
- If it contains all of a set of terms and symbols that occur in RDF/JSON then it's most likely RDF/JSON. These terms are "value","type",{,},[ and ]
- Otherwise try it as NTriples, NTriples has no real distinctive syntax so hard to test if it's NTriples other than by parsing it
Parse(IGraph, string, IRdfReader)
Parses a raw RDF String using the given IRdfReader.
Declaration
public static void Parse(IGraph g, string data, IRdfReader reader)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to load into. |
string | data | Raw RDF String. |
IRdfReader | reader | Parser to use to read the data. |
Remarks
Use this when you have a raw RDF string and you know the syntax the RDF is in.
ParseDataset(ITripleStore, string)
Parses a raw RDF Dataset String (attempts to auto-detect the format).
Declaration
public static void ParseDataset(ITripleStore store, string data)
Parameters
Type | Name | Description |
---|---|---|
ITripleStore | store | Store to load into. |
string | data | Raw RDF Dataset String. |
Remarks
Auto-detection is based on testing the string to see if it contains certain keyword constructs which might indicate a particular syntax has been used. This detection may not always be accurate.
ParseDataset(ITripleStore, string, IStoreReader)
Parses a raw RDF Dataset String using the given Parser.
Declaration
public static void ParseDataset(ITripleStore store, string data, IStoreReader reader)
Parameters
Type | Name | Description |
---|---|---|
ITripleStore | store | Store to load into. |
string | data | Raw RDF Dataset String. |
IStoreReader | reader | Parser to use. |
ParseResultSet(SparqlResultSet, string)
Parses a raw SPARQL Results String (attempts to auto-detect the format).
Declaration
public static void ParseResultSet(SparqlResultSet results, string data)
Parameters
Type | Name | Description |
---|---|---|
SparqlResultSet | results | SPARQL Result Set to fill. |
string | data | Raw SPARQL Results String. |
Remarks
Auto-detection is based on testing the string to see if it contains certain keyword constructs which might indicate a particular syntax has been used. This detection may not always be accurate.
ParseResultSet(SparqlResultSet, string, ISparqlResultsReader)
Parses a raw SPARQL Results String using the given Parser.
Declaration
public static void ParseResultSet(SparqlResultSet results, string data, ISparqlResultsReader reader)
Parameters
Type | Name | Description |
---|---|---|
SparqlResultSet | results | SPARQL Result Set to fill. |
string | data | Raw SPARQL Results String. |
ISparqlResultsReader | reader | Parser to use. |