Class GraphHelper
java.lang.Object
com.janeirodigital.shapetrees.core.helpers.GraphHelper
Assorted helper methods related to RDF Graphs
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.jena.graph.Graph
Creates an empty Graph with initialized prefixesstatic org.apache.jena.riot.Lang
getLangForContentType
(String contentType) Determine the Jena language (graph serialization type) based on a content type stringstatic URL
static org.apache.jena.graph.Triple
Create a new triple statement with stringsstatic org.apache.jena.graph.Triple
Create a new triple statement with URIsstatic URL
nodeToUrl
(org.apache.jena.graph.Node node) Convert an RDFNode value to URLstatic org.apache.jena.graph.Graph
readStringIntoGraph
(URI baseURI, String rawContent, String contentType) Deserializes a string into a Graphstatic org.apache.jena.rdf.model.Model
readStringIntoModel
(URI baseURI, String rawContent, String contentType) Deserializes a string into a Modelstatic URL
removeUrlFragment
(URL url) Remove a fragment from a URL.static URI
Wrap conversion from URL to URI which should never fail on a well-formed URL.static String
writeGraphToTurtleString
(org.apache.jena.graph.Graph graph) Writes a graph into a turtle serialization
-
Method Details
-
getLangForContentType
Determine the Jena language (graph serialization type) based on a content type string- Parameters:
contentType
- Content type string- Returns:
- Serialization language
-
writeGraphToTurtleString
Writes a graph into a turtle serialization- Parameters:
graph
- Graph to serialize- Returns:
- String in TTL serialization
-
readStringIntoModel
public static org.apache.jena.rdf.model.Model readStringIntoModel(URI baseURI, String rawContent, String contentType) throws ShapeTreeException Deserializes a string into a Model- Parameters:
baseURI
- Base URI to use for statementsrawContent
- String of RDFcontentType
- Content type of content- Returns:
- Deserialized model
- Throws:
ShapeTreeException
- ShapeTreeException
-
readStringIntoGraph
public static org.apache.jena.graph.Graph readStringIntoGraph(URI baseURI, String rawContent, String contentType) throws ShapeTreeException Deserializes a string into a Graph- Parameters:
baseURI
- Base URI to use for statementsrawContent
- String of RDFcontentType
- Content type of content- Returns:
- Deserialized graph
- Throws:
ShapeTreeException
- ShapeTreeException
-
getEmptyGraph
public static org.apache.jena.graph.Graph getEmptyGraph()Creates an empty Graph with initialized prefixes- Returns:
- Graph Empty Graph
-
newTriple
public static org.apache.jena.graph.Triple newTriple(URI subject, URI predicate, Object object) throws ShapeTreeException Create a new triple statement with URIs- Parameters:
subject
- Subject to includepredicate
- Predicate to includeobject
- Object to include- Returns:
- Throws:
ShapeTreeException
-
newTriple
public static org.apache.jena.graph.Triple newTriple(String subject, String predicate, Object object) throws ShapeTreeException Create a new triple statement with strings- Parameters:
subject
- Subject to includepredicate
- Predicate to includeobject
- Object to include- Returns:
- Throws:
ShapeTreeException
-
urlToUri
Wrap conversion from URL to URI which should never fail on a well-formed URL.- Parameters:
url
- covert this URL to a URI- Returns:
- IRI java native object for a URI (useful for Jena graph operations)
-
nodeToUrl
Convert an RDFNode value to URL- Parameters:
node
- RDFNode to convert- Returns:
- Converted URL
- Throws:
ShapeTreeException
-
removeUrlFragment
Remove a fragment from a URL. Returns the same URL if there is no fragment- Parameters:
url
- to remove fragment from- Returns:
- URL without fragment
-
knownUrl
-