Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.UriRef


  @Override
  public void map(CAS cas, String graphName) throws CASMappingException {

    // This is creating the Graph for the annotation in Annotation Ontology format
    final TcManager tcManager = TcManager.getInstance();
    final UriRef mGraphName = new UriRef(graphName);

    GraphNode node = new GraphNode(new BNode(), tcManager.createMGraph(mGraphName));
    Lock lock = node.writeLock();
    try {
      lock.lock();

      SelectorRegistry selectorRegistry = new SelectorRegistry();
      // Iterate the annotations to create an index of them up front, this
      // is incase we have references between
      // annotations and need to output the appropriate RDF identifier out
      // of sequence
      Map<Annotation, Integer> annotIndex = new HashMap<Annotation, Integer>();
      int annotCnt = 0;
      for (FeatureStructure uimaObject : UIMAUtils.getAllFSofType(TOP.type, cas.getJCas())) {

          // set Annotation specific properties for the node
          if (uimaObject instanceof Annotation) {
            // If type is DocumentAnnotation I skip it
              if (uimaObject.getType().toString().equals("uima.tcas.DocumentAnnotation")) {
                continue;
              }

              // Get persistent URI for region in document
              Annotation annot = (Annotation) uimaObject;
              log.info("annotation index " + annotCnt);
              annotIndex.put(annot, annotCnt);
              annotCnt++;
          }
      }

      UriRef annotationSetUri = new UriRef(
              new StringBuilder(AO.AnnotationSet.getUnicodeString()).toString());
      log.info("AO: Annotation set uri " + annotationSetUri);

      GraphNode annotationSet = new GraphNode(annotationSetUri, node.getGraph());
      log.info(new StringBuilder("AO: Set created ").toString());
      annotationSet.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
              AO.AnnotationSet);

      for (FeatureStructure uimaObject : UIMAUtils.getAllFSofType(TOP.type, cas.getJCas())) {

        // set Annotation specific properties for the node
        if (uimaObject instanceof Annotation) {

          // If type is DocumentAnnotation I skip it
          if (uimaObject.getType().toString().equals("uima.tcas.DocumentAnnotation")) {
            continue;
          }

          // Get persistent URI for region in document
          Annotation annot = (Annotation) uimaObject;
          UriRef selectorUri = selectorRegistry.get(annot.getBegin(), annot.getEnd());

          // Annotation URI
          int annotId = annotIndex.get((Annotation) uimaObject);
          UriRef annotationUri = new UriRef(new StringBuilder(AO.Annotation.getUnicodeString())
                  .append("/").append(annotId).toString());
          log.info("annotation uri " + annotationUri);

          // Annotation Graph
          GraphNode annotationNode = new GraphNode(annotationUri, annotationSet.getGraph());
          log.info(new StringBuilder("AO: Node created for Type ").append(
                  uimaObject.getType().toString()).toString());
          annotationNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                  new UriRef("http://purl.org/ao/Annotation"));

          annotationNode.addProperty(AO.context, selectorUri);

          // finally add the triple to the existing node
          annotationSet.addProperty(AO.item, annotationNode.getNode());
        }
      }

      Iterator<SelectorRegistry.Selector> iterator = selectorRegistry.iterator();
      while (iterator.hasNext()) {

        SelectorRegistry.Selector sel = iterator.next();

        // Get persistent URI for region in document
        UriRef selectorUri = sel.uri;

        // create a new feature node
        GraphNode selectorNode = new GraphNode(selectorUri, node.getGraph());
        log.info(new StringBuilder("Node created for Selector " + selectorUri).toString());

        String documentText = cas.getDocumentText();
        selectorNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                AO.Selector);
        selectorNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                AOSELECTORS.OffsetRangeTextSelector);
        selectorNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
                AOSELECTORS.PrefixPostfixTextSelector);
        selectorNode.addPropertyValue(AOSELECTORS.exact, getSpan(documentText, sel.start, sel.end));
        selectorNode.addPropertyValue(AOSELECTORS.prefix,
                getSpan(documentText, sel.start - 50, sel.start));
        selectorNode.addPropertyValue(AOSELECTORS.postfix,
View Full Code Here


  @Override
  public GraphNode getExceptionGraphNode() {
    GraphNode result = new GraphNode(new BNode(), new SimpleMGraph());
    result.addProperty(RDF.type, TYPERENDERING.Exception);
    LiteralFactory factory = LiteralFactory.getInstance();
    result.addProperty(TYPERENDERING.errorSource, new UriRef(renderingSpecification.toString()));
    if (lineNumber != -1) {
      result.addProperty(TYPERENDERING.line, factory.createTypedLiteral(new Integer(lineNumber)));
    }
    if (columnNumber != -1) {
      result.addProperty(TYPERENDERING.column, factory.createTypedLiteral(Integer.valueOf(columnNumber)));
View Full Code Here

  private MGraph getDocumentationMGraph(URL docUrl, String symbolicName) {
    try {
      Graph parsedGraph = parser.parse(docUrl.openStream(),
          SupportedFormat.N_TRIPLE);
      UriRef baseUri = config.getDefaultBaseUri();
      return new SimpleMGraph(new UriMutatorIterator(
          parsedGraph.iterator(), baseUri.getUnicodeString(), symbolicName));
    } catch (IOException ex) {
      logger.warn("Cannot parse documentation at URL: {}", docUrl);
      throw new RuntimeException(ex);
    }
  }
View Full Code Here

   *
   * @param bundle
   * @param docMGraph
   */
  private void addAdditionalTriples(Bundle bundle, MGraph docMGraph) {
    UriRef bundleUri = new UriRef(bundle.getLocation());
    Triple triple = new TripleImpl(bundleUri, RDF.type, OSGI.Bundle);
    docMGraph.add(triple);
    Iterator<Triple> titledContents = docMGraph.filter(null, RDF.type,
        DISCOBITS.TitledContent);
    Set<Triple> newTriples = new HashSet<Triple>();
View Full Code Here

    }
    return null;
  }

  private UriRef createRandomUriRef() {
    return new UriRef("http://" + UUID.randomUUID().toString());
  }
View Full Code Here

      public UriRef getThumbnailUri(UriRef infoBitUri, Integer width, Integer height, boolean exact) {
        Assert.assertEquals(uri, infoBitUri);
        Assert.assertEquals(Integer.valueOf(700), width);
        Assert.assertEquals(Integer.valueOf(300), height);
        Assert.assertEquals(true, exact);
        return new UriRef("http://example.com/test");
      }       
    }));
   
    out.write(input);
    Assert.assertEquals("<img href=\"http://example.com/test\" />", bous.toString());
View Full Code Here

    metaData.add(new IptcDataSet(IptcDataSet.KEYWORDS, "keyword3"));
    metaData.add(new IptcDataSet(IptcDataSet.CITY, "City"));
   
    TripleCollection tc = MetaDataUtils.convertIptcToXmp(metaData);

    Iterator<Triple> it = tc.filter(null, new UriRef(DC.subject.getURI()), null);
    it = tc.filter((NonLiteral) it.next().getObject(), null, null);
    while(it.hasNext()) {
      Triple triple = it.next();
      Assert.assertTrue(
          triple.getObject().toString().contains("keyword1") ||
          triple.getObject().toString().contains("keyword2") ||
          triple.getObject().toString().contains("keyword3") ||
          triple.getObject().toString().contains(RDF.Bag.getURI()));
    }

    Assert.assertTrue(tc.filter(null,
        new UriRef("http://ns.adobe.com/photoshop/1.0/City"),
        new PlainLiteralImpl("City")).hasNext());
  }
View Full Code Here

    metaData2.add(new ExifTagDataSet(ExifTagDataSet.UserComment, "Bla Bla Bla"));
    metaData2.add(new ExifTagDataSet(ExifTagDataSet.Artist, "Hans Wurst"));
   
    TripleCollection tc = MetaDataUtils.convertExifToXmp(metaData2);
   
    Iterator<Triple> it = tc.filter(null, new UriRef("http://ns.adobe.com/exif/1.0/UserComment"), null);
    it = tc.filter((NonLiteral) it.next().getObject(), null, null);
    while(it.hasNext()) {
      Triple triple = it.next();
      Assert.assertTrue(
          triple.getObject().toString().contains("Bla Bla Bla") ||
          triple.getObject().toString().contains(RDF.Alt.getURI()));
    }
   
    Assert.assertTrue(tc.filter(null,
        new UriRef("http://ns.adobe.com/tiff/1.0/Artist"),
        new PlainLiteralImpl("Hans Wurst")).hasNext());
   
  }
View Full Code Here

  @Test
  public void testGetSameBNode() throws Exception {
    MGraph graph = getEmptyMGraph();
    BNode bNode = new BNode();
    final UriRef HAS_NAME = new UriRef("http://example.org/ontology/hasName");
    final PlainLiteralImpl name = new PlainLiteralImpl("http://example.org/people/alice");
    final PlainLiteralImpl name2 = new PlainLiteralImpl("http://example.org/people/bob");
    final Triple tripleAlice = new TripleImpl(bNode, HAS_NAME, name);
    final Triple tripleBob = new TripleImpl(bNode, HAS_NAME, name2);
    Assert.assertTrue(graph.add(tripleAlice));
View Full Code Here

    Iterator<Triple> iterator;
    Collection<Triple> resultSet;

    // Find bob
    iterator = graph.filter(null, null,
        new UriRef("http://example.org/people/bob"));
    resultSet= toCollection(iterator);
    Assert.assertEquals(1, resultSet.size());
    Assert.assertTrue(resultSet.contains(tripleBob));

    // Find alice
    iterator = graph.filter(null, null,
        new UriRef("http://example.org/people/alice"));
    resultSet= toCollection(iterator);
    Assert.assertEquals(1, resultSet.size());
    Assert.assertTrue(resultSet.contains(tripleAlice));

    // Find both
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.UriRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.