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.GraphCreates an empty Graph with initialized prefixesstatic org.apache.jena.riot.LanggetLangForContentType(String contentType) Determine the Jena language (graph serialization type) based on a content type stringstatic URLstatic org.apache.jena.graph.TripleCreate a new triple statement with stringsstatic org.apache.jena.graph.TripleCreate a new triple statement with URIsstatic URLnodeToUrl(org.apache.jena.graph.Node node) Convert an RDFNode value to URLstatic org.apache.jena.graph.GraphreadStringIntoGraph(URI baseURI, String rawContent, String contentType) Deserializes a string into a Graphstatic org.apache.jena.rdf.model.ModelreadStringIntoModel(URI baseURI, String rawContent, String contentType) Deserializes a string into a Modelstatic URLremoveUrlFragment(URL url) Remove a fragment from a URL.static URIWrap conversion from URL to URI which should never fail on a well-formed URL.static StringwriteGraphToTurtleString(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
-