Package org.apache.clerezza.rdf.core

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


    graph.add(jena2TriaUtil.convertTriple(triple));
  }

  @Override
  public void performDelete(com.hp.hpl.jena.graph.Triple triple) {
    Triple clerezzaTriple = jena2TriaUtil.convertTriple(triple);
    if (clerezzaTriple != null) {
      graph.remove(clerezzaTriple);
    }
  }
View Full Code Here


        return base.hasNext();
      }

      @Override
      public com.hp.hpl.jena.graph.Triple next() {
        Triple baseNext = base.next();
        lastReturned = baseNext;
        return (baseNext == null) ? null : tria2JenaUtil.convertTriple(baseNext, true);
      }

      @Override
View Full Code Here

      throw new IllegalStateException(
          "Encoding 'UTF-8' is not supported by this System", e);
    }
    Triple[] sortedTriples = tc.toArray(new Triple[tc.size()]);
    Arrays.sort(sortedTriples, SUBJECT_COMPARATOR);
    Triple triple;
    NonLiteral subject = null;
    String subjectStr = null;
    UriRef predicate = null;
    Map<UriRef, JSONArray> predicateValues = new HashMap<UriRef, JSONArray>();
    JSONObject jSubject = new JSONObject();
    try {
      out.write("{"); // start the root object
      for (int i = 0; i < sortedTriples.length; i++) {
        triple = sortedTriples[i];
        boolean subjectChange = !triple.getSubject().equals(subject);
        if (subjectChange) {
          if (subject != null) {
            // write the predicate values
            for (Entry<UriRef, JSONArray> predicates : predicateValues
                .entrySet()) {
              jSubject.put(
                  predicates.getKey().getUnicodeString(),
                  predicates.getValue());
            }
            // write subject
            out.write(JSONObject.toString(subjectStr, jSubject));
            out.write(",");
            jSubject.clear(); // just clear
            predicateValues.clear();
          }
          // init next subject
          subject = triple.getSubject();
          if (subject instanceof BNode) {
            subjectStr = bNodeMgr.getBNodeId((BNode) subject);
          } else { // if (subject instanceof UriRef)
            subjectStr = ((UriRef) subject).getUnicodeString();
          }
        }
        predicate = triple.getPredicate();
        JSONArray values = predicateValues.get(predicate);
        if (values == null) {
          values = new JSONArray();
          predicateValues.put(predicate, values);
        }
        values.add(writeObject(bNodeMgr, triple.getObject()));
      }
      if (subjectStr != null) {
        for (Entry<UriRef, JSONArray> predicates : predicateValues
            .entrySet()) {
          jSubject.put(predicates.getKey().getUnicodeString(),
View Full Code Here

        while (resultSet.hasNext()) {
            SolutionMapping mapping = resultSet.next();
            UriRef ref = (UriRef) mapping.get("enhID");
            Iterator<Triple> tripleItr = this.getEnhancementGraph().filter(ref, null, null);
            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                willBeRemoved.add(triple);
            }
        }

        enhancementGraph.removeAll(willBeRemoved);
View Full Code Here

        while (resultSet.hasNext()) {
            SolutionMapping mapping = resultSet.next();
            UriRef ref = (UriRef) mapping.get("enhID");
            Iterator<Triple> tripleItr = this.getEnhancementGraph().filter(ref, null, null);
            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                metadata.add(triple);
            }
        }
        ContentItem ci = null;
        try {
View Full Code Here

    // }

    /* Removes the value in lose confidence from the graph */
    protected void removeOldConfidenceFromGraph(MGraph graph, List<Triple> loseConfidence) {
        for (int i = 0; i < loseConfidence.size(); i++) {
            Triple elementToRemove = loseConfidence.get(i);
            graph.remove(elementToRemove);
        }
    }
View Full Code Here

        Iterator<Triple> it = graph.filter(entityAnnotation, null, null);
        // we can not add triples to the graph while iterating. So store them
        // in a list and add later
        List<Triple> added = new ArrayList<Triple>(32);
        while (it.hasNext()) {
            Triple triple = it.next();
            if (DC_RELATION.equals(triple.getPredicate())) {
                if (triple.getObject().equals(textAnnotation)) {
                    // remove the dc relation to the currently processed
                    // textAnnotation from the original
                    it.remove();
                    // and add it to the copy
                    added.add(new TripleImpl(copy, // use the copy as subject!
                            triple.getPredicate(), triple.getObject()));
                } // else it is not the currently processed TextAnnotation
                  // so we need to keep in in the original and NOT add
                  // it to the copy
            } else { // we can copy all other information 1:1
                added.add(new TripleImpl(copy, // use the copy as subject!
                        triple.getPredicate(), triple.getObject()));
            }
        }
        graph.addAll(added);
        return copy;
    }
View Full Code Here

            Literal endLiteral = literalFactory.createTypedLiteral(tag.getEnd());
            //search for existing text annotation
            Iterator<Triple> it = metadata.filter(null, ENHANCER_START, startLiteral);
            UriRef textAnnotation = null;
            while(it.hasNext()){
                Triple t = it.next();
                if(metadata.filter(t.getSubject(), ENHANCER_END, endLiteral).hasNext() &&
                        metadata.filter(t.getSubject(), RDF_TYPE, ENHANCER_TEXTANNOTATION).hasNext()){
                    textAnnotation = (UriRef)t.getSubject();
                    break;
                }
            }
            if(textAnnotation == null){ //not found ... create a new one
                textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
View Full Code Here

    private MGraph extractRepresentation(TripleCollection source,MGraph target, NonLiteral node, Set<BNode> visited){
        //we need all the outgoing relations and also want to follow bNodes until
        //the next UriRef. However we are not interested in incoming relations!
        Iterator<Triple> outgoing = source.filter((NonLiteral) node, null, null);
        while (outgoing.hasNext()) {
            Triple triple = outgoing.next();
            target.add(triple);
            Resource object = triple.getObject();
            if(object instanceof BNode){
                //add first and than follow because there might be a triple such as
                // bnode1 <urn:someProperty> bnode1
                visited.add((BNode)object);
                extractRepresentation(source, target, (NonLiteral)object, visited);
View Full Code Here

        Iterator<Triple> tripleIterator = graph.filter(null, targetResourcePredicate, targetResourceValue);
        List<NonLiteral> processedURIs = new ArrayList<NonLiteral>();

        // add cms object annotations
        while (tripleIterator.hasNext()) {
            Triple t = tripleIterator.next();
            NonLiteral subject = t.getSubject();
            String name = getObjectName(subject, nameResource, graph, false);

            // There should be a valid name for CMS Object
            if (!name.contentEquals("")) {
                graph.add(new TripleImpl(subject, RDFBridgeHelper.RDF_TYPE, CMSAdapterVocabulary.CMS_OBJECT));
View Full Code Here

TOP

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

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.