Class NormalizeAnnotation

java.lang.Object
de.wwu.scdh.annotation.selection.wadm.NormalizeAnnotation
All Implemented Interfaces:
Consumer<org.apache.jena.rdf.model.Resource>

public class NormalizeAnnotation extends Object implements Consumer<org.apache.jena.rdf.model.Resource>
NormalizeAnnotation can be used to normalize or rewrite the WADM annotations targeting a given resource in a graph.

This class implements the Consumer interface and can thus be used in a functional style like forEach(new NormalizeAnnoation(...)) on some resource iterator. The normalization will--by side effect--be written to the Model which was passed into the constructor.

USAGE: Use the static methods normalize to do the normalization.

  • Field Details

    • resource

      protected final Resource<?> resource
    • iri

      protected final URI iri
    • rewriteIri

      protected final Optional<URI> rewriteIri
    • model

      protected org.apache.jena.rdf.model.Model model
    • rewriterFactory

      protected final RewriterFactory rewriterFactory
    • normalizerConfig

      protected final RewriterConfig normalizerConfig
    • error

      protected Optional<Exception> error
  • Constructor Details

  • Method Details

    • accept

      public void accept(org.apache.jena.rdf.model.Resource annotation)
      This is the method of the function interface Consumer and actually does the normalization without throwing errors.
      Specified by:
      accept in interface Consumer<org.apache.jena.rdf.model.Resource>
    • getModel

      public org.apache.jena.rdf.model.Model getModel()
      Returns the Model. The model is normalized, when accept was called.
    • normalize

      public static org.apache.jena.rdf.model.Model normalize(Resource<?> resource, URI iri, RewriterFactory rewriterFactory, RewriterConfig normalizerConfig, org.apache.jena.rdf.model.Model model)
      Normalize all annotations in the provided Model.
      Parameters:
      resource - - the resource the rewriting has to done with
      iri - - the IRI of sources (oa:hasSource) the rewriting has to done on
      rewriterFactory - - a factory that returns a rewriter for a point
      normalizerConfig - - a configuration
      model - - the RDF model (graph) containing the annotations
      Returns:
      the normalized Model
    • rewrite

      public static org.apache.jena.rdf.model.Model rewrite(Resource<?> resource, URI iri, URI rewriteIri, RewriterFactory rewriterFactory, RewriterConfig normalizerConfig, org.apache.jena.rdf.model.Model model)
      Rewrite all annotations in the provided Model. In contrast to normalize(de.wwu.scdh.annotation.selection.Resource, URI, RewriterFactory, RewriterConfig, Model) this method also rewrites the oa:hasSource property and is thus suitable for transforming selectors between representations.
      Parameters:
      resource - - the resource the rewriting has to done with, should be a MappedResource
      iri - - the IRI of sources (oa:hasSource) the rewriting has to done on
      rewriteIri - - the new IRI of rewritten targets
      rewriterFactory - - a factory that returns a rewriter for a point
      normalizerConfig - - a configuration
      model - - the RDF model (graph) containing the annotations
      Returns:
      the rewritten Model
    • normalize

      public static org.apache.jena.rdf.model.Model normalize(Resource<?> resource, URI iri, RewriterFactory rewriterFactory, RewriterConfig normalizerConfig, String graph, Optional<String> lang)
      Normalize all annotations in a Model given by a URI as String which may reference a local file (file URI) or an online resource.

      Note, that this method sets options to the RDF parser, e.g., the StaticDocumentLoader as JSON-LD document loader. If you want full control over RDF parsing, the use normalize(de.wwu.scdh.annotation.selection.Resource, URI, RewriterFactory, RewriterConfig, Model) instead.

      Parameters:
      resource - - the resource the rewriting has to done with
      iri - - the IRI of sources (oa:hasSource) the rewriting has to done on
      rewriterFactory - - a factory that returns a rewriter for a point
      normalizerConfig - - a configuration
      graph - - the URI where to read the RDF from
      lang - - the serialization language of the graph at the URI
      Returns:
      the normalized Model
    • rewrite

      public static org.apache.jena.rdf.model.Model rewrite(Resource<?> resource, URI iri, URI rewriteIri, RewriterFactory rewriterFactory, RewriterConfig normalizerConfig, String graph, Optional<String> lang)
      Rewrite all annotations in the provided Model. In contrast to normalize(de.wwu.scdh.annotation.selection.Resource, URI, RewriterFactory, RewriterConfig, String, Optional) this method also rewrites the oa:hasSource property and is thus suitable for transforming selectors between representations.

      Note, that this method sets options to the RDF parser, e.g., the StaticDocumentLoader as JSON-LD document loader. If you want full control over RDF parsing, the use rewrite(de.wwu.scdh.annotation.selection.Resource, URI, URI, RewriterFactory, RewriterConfig, Model) instead.

      Parameters:
      resource - - the resource the rewriting has to done with. Should be a MappedResource.
      iri - - the IRI of sources (oa:hasSource) the rewriting has to done on
      rewriteIri - - the new IRI of rewritten targets
      rewriterFactory - - a factory that returns a rewriter for a point
      normalizerConfig - - a configuration
      graph - - the URI where to read the RDF from
      lang - - the serialization language of the graph at the URI
      Returns:
      the rewritten Model
    • normalize

      public static org.apache.jena.rdf.model.Model normalize(Resource<?> resource, URI iri, RewriterFactory rewriterFactory, RewriterConfig normalizerConfig, InputStream input, Optional<String> lang, Optional<String> modelBase)
      Normalize all annotations in a Model which is read from an InputStream.

      Note, that this method sets options to the RDF parser, e.g., the StaticDocumentLoader as JSON-LD document loader. If you want full control over RDF parsing, the use normalize(de.wwu.scdh.annotation.selection.Resource, URI, RewriterFactory, RewriterConfig, Model) instead.

      Parameters:
      resource - - the resource the rewriting has to done with
      iri - - the IRI of sources (oa:hasSource) the rewriting has to done on
      rewriterFactory - - a factory that returns a rewriter for a point
      normalizerConfig - - a configuration
      input - - the InputStream
      lang - - optionally the serialization language of stream data; if not provided, NTriples are assumed
      modelBase - - a base URI of the model, given as String
      Returns:
      the normalized Model
    • rewrite

      public static org.apache.jena.rdf.model.Model rewrite(Resource<?> resource, URI iri, URI rewriteIri, RewriterFactory rewriterFactory, RewriterConfig normalizerConfig, InputStream input, Optional<String> lang, Optional<String> modelBase)
      Rewrite all annotations in the provided Model. In contrast to normalize(de.wwu.scdh.annotation.selection.Resource, URI, RewriterFactory, RewriterConfig, InputStream, Optional, Optional) this method also rewrites the oa:hasSource property and is thus suitable for transforming selectors between representations.

      Note, that this method sets options to the RDF parser, e.g., the StaticDocumentLoader as JSON-LD document loader. If you want full control over RDF parsing, the use rewrite(de.wwu.scdh.annotation.selection.Resource, URI, URI, RewriterFactory, RewriterConfig, Model) instead. *

      Parameters:
      resource - - the resource the rewriting has to done with. Should be a MappedResource.
      iri - - the IRI of sources (oa:hasSource) the rewriting has to done on
      rewriterFactory - - a factory that returns a rewriter for a point
      normalizerConfig - - a configuration
      input - - the InputStream
      lang - - optionally the serialization language of stream data; if not provided, NTriples are assumed
      modelBase - - a base URI of the model, given as String
      Returns:
      the rewritten Model