Class GraphHelper

java.lang.Object
com.janeirodigital.shapetrees.core.helpers.GraphHelper

public class GraphHelper extends Object
Assorted helper methods related to RDF Graphs
  • Method Details

    • getLangForContentType

      public static org.apache.jena.riot.Lang getLangForContentType(String contentType)
      Determine the Jena language (graph serialization type) based on a content type string
      Parameters:
      contentType - Content type string
      Returns:
      Serialization language
    • writeGraphToTurtleString

      public static String writeGraphToTurtleString(org.apache.jena.graph.Graph graph)
      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 statements
      rawContent - String of RDF
      contentType - 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 statements
      rawContent - String of RDF
      contentType - 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 include
      predicate - Predicate to include
      object - 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 include
      predicate - Predicate to include
      object - Object to include
      Returns:
      Throws:
      ShapeTreeException
    • urlToUri

      public static URI urlToUri(URL url)
      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

      public static URL nodeToUrl(org.apache.jena.graph.Node node) throws ShapeTreeException
      Convert an RDFNode value to URL
      Parameters:
      node - RDFNode to convert
      Returns:
      Converted URL
      Throws:
      ShapeTreeException
    • removeUrlFragment

      public static URL removeUrlFragment(URL url)
      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

      public static URL knownUrl(String urlString)