Package org.apache.clerezza.rdf.utils

Examples of org.apache.clerezza.rdf.utils.GraphNode


    // 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,
                getSpan(documentText, sel.end, sel.end + 50));
        selectorNode.addPropertyValue(AOSELECTORS.offset, sel.start);
        selectorNode.addPropertyValue(AOSELECTORS.range, sel.end);
      }

      TripleCollection tc = node.getGraph();
      for (Triple t : tc) {
        log.info(t.toString());
View Full Code Here


    return sb.toString();
  }

  @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)));
    }
    result.addProperty(TYPERENDERING.message, new PlainLiteralImpl(getMessage()));
    return result;
  }
View Full Code Here

  }

  @Override
  public void render(final UriRef resource, GraphNode context, String mode,
      OutputStream os) throws IOException {
    final GraphNode resourceNode = AccessController.doPrivileged( new PrivilegedAction<GraphNode>() {
          @Override
          public GraphNode run() {
            return graphNodeProvider.get(resource);
          }
        });
View Full Code Here

    }
  }

  private void createFile(NonLiteral docRoot, Graph documentationGraph,
      File outFile) throws IOException {
    GraphNode docRootNode = new GraphNode(docRoot, documentationGraph);
      Renderer renderer = rendererFactory.createRenderer(docRootNode, null,
          Collections.singletonList(MediaType.APPLICATION_XHTML_XML_TYPE));
      FileOutputStream out = new FileOutputStream(outFile);
      try {
        System.out.println("writing " + outFile);
View Full Code Here

      NonLiteral languageUri = (NonLiteral) languageDescription.getResource().getNode();
      list.add(languageUri);
      if (copyToNode) {
        readLock.lock();
        try {
          graph.addAll(new GraphNode(languageUri, configGraph).getNodeContext());
        } finally {
          readLock.unlock();
        }
      }
    }
    node.addProperty(PLATFORM.instance, platformInstance);
    graph.add(new TripleImpl(platformInstance, RDF.type, PLATFORM.Instance));
    graph.add(new TripleImpl(platformInstance, PLATFORM.languages, listNode));
    graph.add(new TripleImpl(listNode, RDF.type, LANGUAGE.LanguageList));
    if (!copyToNode) {
      node = new GraphNode(node.getNode(), new UnionMGraph(graph, configGraph));
    }
    return node;
  }
View Full Code Here

  protected void unbindContextProvider(UserContextProvider provider) {
    contextProviders.remove(provider);
  }

  private GraphNode getUserContext() {
    GraphNode contextNode = new GraphNode(new BNode(), new SimpleMGraph());
    synchronized(contextProviders) {
      Iterator<UserContextProvider> providersIter = contextProviders.iterator();
      while (providersIter.hasNext()) {
        UserContextProvider userContextProvider = providersIter.next();
        contextNode = userContextProvider.addUserContext(contextNode);
View Full Code Here

  public List<LanguageDescription> getLanguages() {
    List<LanguageDescription> langList = new ArrayList<LanguageDescription>();
    Iterator<Resource> languages = languageListCache.iterator();
    while (languages.hasNext()) {
      UriRef language = (UriRef) languages.next();
      langList.add(new LanguageDescription(new GraphNode(language, getConfigGraph())));
    }
    return langList;
  }
View Full Code Here

   * of the platform.
   * @return the language description of the default language.
   */
  public LanguageDescription getDefaultLanguage() {
    return new LanguageDescription(
        new GraphNode(languageListCache.get(0), getConfigGraph()));
  }
View Full Code Here

   */
  public UriRef getLanguage(String languageName, Language inLanguage) {
    Graph lingvojGraph = getLingvojGraph();
    Iterator<Triple> languages = lingvojGraph.filter(null, RDFS.isDefinedBy, null);
    while (languages.hasNext()) {
      GraphNode languageNode = new GraphNode((UriRef) languages.next().getSubject(), lingvojGraph);
      Iterator<Resource> labels = languageNode.getObjects(RDFS.label);
      while (labels.hasNext()) {
        PlainLiteral label = (PlainLiteral) labels.next();
        if (label.getLanguage().equals(inLanguage) || inLanguage == null) {
          if (label.getLexicalForm().contains(languageName)) {
            return (UriRef) languageNode.getNode();
          }
        }
      }
    }
    return null;
View Full Code Here

   *
   * @param languageUri The language uri which specifies the language
   */
  public GraphNode getLanguageNode(NonLiteral langUri) {
    Graph lingvojRdf = getLingvojGraph();
    return new GraphNode(langUri, lingvojRdf);
  }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.utils.GraphNode

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.