org.openimaj.rdf.serialize

Class RDFSerializer

    • Constructor Summary

      Constructors 
      Constructor and Description
      RDFSerializer()
      Default constructor
      RDFSerializer(boolean autoPredicate)
      Constructor that determines whether to create predicates automatically when the Predicate annotation does not exist.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addTriple(org.openrdf.model.Statement t)
      Adds a single triple to some RDF serializer.
      org.openrdf.model.impl.URIImpl getObjectURI(Object obj, org.openrdf.model.impl.URIImpl defaultURI)
      Returns a URI for the given object.
      org.openrdf.model.URI serialize(Object objectToSerialize, String uri)
      Serialize the given object as RDF.
      org.openrdf.model.URI serializeAux(Object objectToSerialize, String uri)
      Serialize the given object as RDF.
      org.openrdf.model.URI serializeAux(Object objectToSerialize, String uri, boolean outputCollectionObjects)
      Serialize the given object as RDF.
      void setAutoPredicate(boolean tf)
      Set whether to attempt to output all fields from the objects, not just those annotated with Predicate.
      void setOutputClassNames(boolean tf)
      Set whether to output class names as triples.
      <T> T unserialize(T objectToUnserialize, String objectRootURI, org.openrdf.repository.Repository repo)
      Unserializes an object from an RDF graph that is rooted at the given URI.
      <T> T unserialize(T objectToUnserialize, String objectRootURI, String rdf, org.openrdf.rio.RDFFormat rdfFormat)
      Unserializes an object from the given RDF string (with the given format) into the given object.
    • Constructor Detail

      • RDFSerializer

        public RDFSerializer(boolean autoPredicate)
        Constructor that determines whether to create predicates automatically when the Predicate annotation does not exist.
        Parameters:
        autoPredicate - Whether to automatically create predicates
    • Method Detail

      • serialize

        public org.openrdf.model.URI serialize(Object objectToSerialize,
                                      String uri)
        Serialize the given object as RDF.
        Parameters:
        objectToSerialize - The object to serialize.
        uri - The URI of the object to serialize.
        Returns:
        Returns the URI of the object (this may be different to the one that's passed in)
      • serializeAux

        public org.openrdf.model.URI serializeAux(Object objectToSerialize,
                                         String uri)
        Serialize the given object as RDF.
        Parameters:
        objectToSerialize - The object to serialize.
        uri - The URI of the object to serialize.
        Returns:
        Returns the URI of the object (this may be different to the one that's passed in)
      • serializeAux

        public org.openrdf.model.URI serializeAux(Object objectToSerialize,
                                         String uri,
                                         boolean outputCollectionObjects)
        Serialize the given object as RDF. This is specifically designed for calling by the process outputting collections.
        Parameters:
        objectToSerialize - The object to serialize.
        uri - The URI of the object to serialize.
        outputCollectionObjects - Whether to output items in a collection
        Returns:
        Returns the URI of the object (this may be different to the one that's passed in)
      • setOutputClassNames

        public void setOutputClassNames(boolean tf)
        Set whether to output class names as triples.
        Parameters:
        tf - TRUE to output class name triples.
      • setAutoPredicate

        public void setAutoPredicate(boolean tf)
        Set whether to attempt to output all fields from the objects, not just those annotated with Predicate.
        Parameters:
        tf - TRUE to attempt to find predicates for all members.
      • unserialize

        public <T> T unserialize(T objectToUnserialize,
                        String objectRootURI,
                        String rdf,
                        org.openrdf.rio.RDFFormat rdfFormat)
        Unserializes an object from the given RDF string (with the given format) into the given object.
        Type Parameters:
        T - Type of object being unserialised
        Parameters:
        objectToUnserialize - The object to populate
        objectRootURI - The URI that gives the root of the object graph
        rdf - The RDF string
        rdfFormat - The format of the RDF in the string
        Returns:
        The populated object or NULL if an error occurs
      • unserialize

        public <T> T unserialize(T objectToUnserialize,
                        String objectRootURI,
                        org.openrdf.repository.Repository repo)
        Unserializes an object from an RDF graph that is rooted at the given URI.
        Type Parameters:
        T - Type of object being unserialised
        Parameters:
        objectToUnserialize - The object to populate
        objectRootURI - The URI that gives the root of the object graph
        repo - The repository storing the RDF graph
        Returns:
        The populated object or NULL if an error occurs
      • getObjectURI

        public org.openrdf.model.impl.URIImpl getObjectURI(Object obj,
                                                  org.openrdf.model.impl.URIImpl defaultURI)
        Returns a URI for the given object. If it cannot determine one, it will return the default URI. It attempts to determine the object's URI by looking for a getURI() method in the object. If it has one, it invokes it and uses the return value as the object's URI, otherwise it will use the default URI passed in via the method parameters.
        Parameters:
        obj - The object
        defaultURI - A default value for the URI
        Returns:
        A URI for the object
      • addTriple

        public void addTriple(org.openrdf.model.Statement t)
        Adds a single triple to some RDF serializer.
        Parameters:
        t - The triple to add