Пример #1
0
  /** Test RDF model of a Context. */
  @Test
  public final void testRdfModel() {
    final Context context =
        new Context("My favorite actress is: Natalie Portman. She is very " + "stunning.", 0, 62);
    final Sentence sentence = NullSentence.getInstance();
    final Model model = ModelFactory.createDefaultModel();

    context.addSentence(sentence);

    final String nif = "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#";
    final Map<String, String> prefixes = new HashMap<>();

    prefixes.put("nif", nif);

    final String base = "http://127.0.0.1/stanfordnlp#";

    prefixes.put("local", base);
    prefixes.put("xsd", "http://www.w3.org/2001/XMLSchema#");

    model.setNsPrefixes(prefixes);

    model.add(
        ResourceFactory.createResource(base + "char=0,62"),
        RDF.type,
        ResourceFactory.createResource(nif + "String"));
    model.add(
        ResourceFactory.createResource(base + "char=0,62"),
        RDF.type,
        ResourceFactory.createResource(nif + "RFC5147String"));
    model.add(
        ResourceFactory.createResource(base + "char=0,62"),
        RDF.type,
        ResourceFactory.createResource(nif + "Context"));
    model.add(
        ResourceFactory.createResource(base + "char=0,62"),
        ResourceFactory.createProperty(nif + "beginIndex"),
        ResourceFactory.createTypedLiteral("0", XSDDatatype.XSDnonNegativeInteger));
    model.add(
        ResourceFactory.createResource(base + "char=0,62"),
        ResourceFactory.createProperty(nif + "endIndex"),
        ResourceFactory.createTypedLiteral("62", XSDDatatype.XSDnonNegativeInteger));
    model.add(
        ResourceFactory.createResource(base + "char=0,62"),
        ResourceFactory.createProperty(nif + "isString"),
        ResourceFactory.createTypedLiteral(
            "My favorite actress is: Natalie Portman. She is very " + "stunning."));

    Assert.assertTrue(
        "Issue to create the model for a Context",
        model.isIsomorphicWith(context.rdfModel("stanfordnlp", NlpProcess.POS)));
  }
Пример #2
0
 private static Property property(String local) {
   return ResourceFactory.createProperty(namespace, local);
 }
Пример #3
0
public class VocabPath {
  public static final Resource start =
      ResourceFactory.createProperty("http://ns.aksw.org/jassa/resource/start");
  public static final Property joinsWith =
      ResourceFactory.createProperty("http://ns.aksw.org/jassa/ontology/joinsWith");
}
Пример #4
0
public class RdfTypeMap
    // extends RdfPopulatorPropertyBase
    extends RdfTypeComplexBase {
  public static final Property entry =
      ResourceFactory.createProperty("http://jsa.aksw.org/ontology/entry");
  public static final Property key =
      ResourceFactory.createProperty("http://jsa.aksw.org/ontology/key");
  public static final Property value =
      ResourceFactory.createProperty("http://jsa.aksw.org/ontology/value");

  public static final Property keyClass =
      ResourceFactory.createProperty("http://jsa.aksw.org/ontology/keyClass");
  public static final Property valueClass =
      ResourceFactory.createProperty("http://jsa.aksw.org/ontology/valueClass");

  // protected MapOps mapOps;
  protected Function<Object, Map> createMapView;

  // , PropertyOps propertyOps, Node predicate, RdfType targetRdfType
  public RdfTypeMap(Function<Object, Map> createMapView) {
    /// super(typeFactory);
    this.createMapView = createMapView;
  }

  @Override
  public void exposeShape(ResourceShapeBuilder shapeBuilder) {
    ResourceShapeBuilder tmp = shapeBuilder.out(entry.asNode());

    tmp.out(key.asNode());
    tmp.out(value.asNode());
  }

  @Override
  public void emitTriples(
      RdfEmitterContext emitterContext,
      Object entity,
      Node subject,
      Graph shapeGraph,
      Consumer<Triple> sink) {

    @SuppressWarnings("unchecked")
    Map<? super Object, ? super Object> map = createMapView.apply(entity);

    int i = 1;
    for (Entry<?, ?> e : map.entrySet()) {
      Object k = e.getKey();
      Object v = e.getValue();

      Node eNode = NodeFactory.createURI(subject.getURI() + "-" + i);

      // persistenceContext.
      // persistenceContext.entityFor(new TypedNode(rdfType, node));

      //            Node kNode = null; // emitterContext.getValueNode(entity,
      // propertyName)//RdfPersistenceContextImpl.getOrCreateRootNode(persistenceContext,
      // typeFactory, k);
      //            Node vNode = null;
      // //RdfPersistenceContextImpl.getOrCreateRootNode(persistenceContext, typeFactory, v);

      //            emitterContext.add(k, entity, "key" + i);
      //            emitterContext.add(v, entity, "value" + i);

      // Node keyNode = emitterContext.

      // Node kNode = emitterContext.getValueNode(entity, "key" + i, v);
      // Node vNode = emitterContext.getValueNode(entity, "value" + i, v);

      Node kNode = emitterContext.requestResolution(k);
      Node vNode = emitterContext.requestResolution(v);

      sink.accept(new Triple(subject, entry.asNode(), eNode));
      sink.accept(new Triple(eNode, key.asNode(), kNode));
      sink.accept(new Triple(eNode, value.asNode(), vNode));

      ++i;
    }
  }

  @Override
  public void populateEntity(
      RdfPersistenceContext persistenceContext,
      Object entity,
      Node subject,
      Graph graph,
      Consumer<Triple> outSink) {
    Model model = ModelFactory.createModelForGraph(graph);
    RDFNode root = ModelUtils.convertGraphNodeToRDFNode(subject, model);

    // <Object, Object>
    Map map = createMapView.apply(entity);

    for (Statement stmt : root.asResource().listProperties(entry).toList()) {
      Resource e = stmt.getObject().asResource();

      Node kNode = e.getProperty(key).getObject().asNode();
      Node vNode = e.getProperty(value).getObject().asNode();

      // TODO: We need to dynamically figure out which entity the node could be
      RdfType rdfType = null;
      Object k =
          persistenceContext.entityFor(
              Object.class, kNode, null); // new TypedNode(rdfType, kNode));
      Object v =
          persistenceContext.entityFor(
              Object.class, vNode, null); // new TypedNode(rdfType, vNode));

      map.put(k, v);
    }
  }

  @Override
  public Class<?> getEntityClass() {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public Node getRootNode(Object obj) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public Object createJavaObject(Node node, Graph graph) {
    @SuppressWarnings("rawtypes")
    Map result = new HashMap();
    return result;
  }

  @Override
  public boolean hasIdentity() {
    // TODO Auto-generated method stub
    return false;
  }

  //    @Override
  //    public Object createJavaObject(Node node) {
  //        //entityOps.
  //        // TODO Auto-generated method stub
  //        return null;
  //    }

}