Package org.apache.clerezza.rdf.core

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


  }

  private static void replaceProp(UriRef subject, UriRef predicate,
      Iterator<Resource> valIter, TripleCollection contentGraph,
      Map.Entry<Property, String> entry) {
    LiteralFactory fac = LiteralFactory.getInstance();
    Set<Triple> triplesToBeRemoved = new HashSet<Triple>();
    if (valIter.hasNext()) {
      triplesToBeRemoved.add(new TripleImpl(subject, predicate, valIter.next()));
    }
    contentGraph.removeAll(triplesToBeRemoved);
    contentGraph.add(new TripleImpl(subject, predicate,
        fac.createTypedLiteral(entry.getValue())));
  }
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)));
    }
    result.addProperty(TYPERENDERING.message, new PlainLiteralImpl(getMessage()));
    return result;
  }
View Full Code Here

  @Test
  public void dateStorage() {
    MGraph graph = getEmptyMGraph();
    Date date = new Date(0);
    LiteralFactory literalFactory = LiteralFactory.getInstance();
    TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
    graph.add(triple);
    Assert.assertTrue(graph.contains(triple));
  }
View Full Code Here

  @Test
  public void dateStorage2() {
    MGraph graph = getEmptyMGraph();
    Date date = new Date(0);
    LiteralFactory literalFactory = LiteralFactory.getInstance();
    TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
    System.out.println(dateLiteral);
    UriRef property = new UriRef("http://example.com/property");
    Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
    graph.add(triple);
View Full Code Here

        confidence
    }

    private void initOccurrences() {
        MGraph graph = contentItem.getMetadata();
        LiteralFactory lf = LiteralFactory.getInstance();
        Map<UriRef,Collection<NonLiteral>> suggestionMap = new HashMap<UriRef,Collection<NonLiteral>>();
        // 1) get Entity Annotations
        Map<NonLiteral,Map<EAProps,Object>> entitySuggestionMap = new HashMap<NonLiteral,Map<EAProps,Object>>();
        Iterator<Triple> entityAnnotations = graph.filter(null, RDF.type, ENHANCER_ENTITYANNOTATION);
        while (entityAnnotations.hasNext()) {
View Full Code Here

    /**
     * @return an RDF/JSON descriptions of places for the word map widget
     */
    public String getPlacesAsJSON() throws ParseException, UnsupportedEncodingException {
        MGraph g = new IndexedMGraph();
        LiteralFactory lf = LiteralFactory.getInstance();
        MGraph metadata = contentItem.getMetadata();
        for (EntityExtractionSummary p : getPlaceOccurrences()) {
            EntitySuggestion bestGuess = p.getBestGuess();
            if (bestGuess == null) {
                continue;
            }
            UriRef uri = new UriRef(bestGuess.getUri());
            Iterator<Triple> latitudes = metadata.filter(uri, GEO_LAT, null);
            if (latitudes.hasNext()) {
                g.add(latitudes.next());
            }
            Iterator<Triple> longitutes = metadata.filter(uri, GEO_LONG, null);
            if (longitutes.hasNext()) {
                g.add(longitutes.next());
                g.add(new TripleImpl(uri, Properties.RDFS_LABEL, lf.createTypedLiteral(bestGuess.getLabel())));
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, g, SupportedFormat.RDF_JSON);

View Full Code Here

            throw new IllegalStateException("Unable to extract Language for " + "ContentItem " + ci.getUri() + ": This is also checked in the canEnhance " + "method! -> This indicated an Bug in the implementation of the " + "EnhancementJobManager!");
        }
        Language lang = new Language(language); //used for the palin literals in TextAnnotations
    try {
      List<SentimentExpression> lista = this.client.extractSentimentExpressions(text, language);
      LiteralFactory literalFactory = LiteralFactory.getInstance();

      MGraph g = ci.getMetadata();

      for (SentimentExpression se : lista) {
        try {
          UriRef textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
          //add selected text as PlainLiteral in the language extracted from the text
          g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTED_TEXT,  new PlainLiteralImpl(se.getSnippetStr(),lang)));
          g.add(new TripleImpl(textAnnotation, DC_TYPE, CeliConstants.SENTIMENT_EXPRESSION));
          if (se.getStartSnippet() != null && se.getEndSnippet() != null) {
            g.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory.createTypedLiteral(se.getStartSnippet().intValue())));
            g.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory.createTypedLiteral(se.getEndSnippet().intValue())));
            g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTION_CONTEXT,
                  new PlainLiteralImpl(getSelectionContext(text, se.getSnippetStr(), se.getStartSnippet()), lang)));
            g.add(new TripleImpl(textAnnotation, CeliConstants.HAS_SENTIMENT_EXPRESSION_POLARITY, literalFactory.createTypedLiteral(se.getSentimentPolarityAsDoubleValue())));
          }
        } catch (NoConvertorException e) {
          log.error(e.getMessage(), e);
        }
      }
View Full Code Here

      throw new EngineException("Error wile encoding/decoding the request/" + "response to the CELI lemmatizer service!", e);
    }
    // get a write lock before writing the enhancements
    ci.getLock().writeLock().lock();
    try {
      LiteralFactory literalFactory = LiteralFactory.getInstance();
      for (LexicalEntry le : terms) {

        List<CeliMorphoFeatures> mFeatures = this.convertLexicalEntryToMorphFeatures(le, language);
        for (CeliMorphoFeatures feat : mFeatures) {
          // Create a text annotation for each interpretation produced by the morphological analyzer
          UriRef textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
          g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTED_TEXT, new PlainLiteralImpl(le.getWordForm(), lang)));
          if (le.from >= 0 && le.to > 0) {
            g.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory.createTypedLiteral(le.from)));
            g.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory.createTypedLiteral(le.to)));
            g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTION_CONTEXT, new PlainLiteralImpl(getSelectionContext(text, le.getWordForm(), le.from), lang)));
          }
          g.addAll(feat.featuresAsTriples(textAnnotation, lang));
        }
      }
View Full Code Here

    }

    @Override
    public MGraph annotateGraph(Graph rawRDF) {
        MGraph graph = new SimpleMGraph(rawRDF);
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        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));
                processedURIs.add(subject);

                /*
                 * if this object has already has name and path annotations, it means that it's already
                 * processed as child of another object. So, don't put new name annotations
                 */
                if (!graph.filter(subject, CMSAdapterVocabulary.CMS_OBJECT_NAME, null).hasNext()) {
                    graph.add(new TripleImpl(subject, CMSAdapterVocabulary.CMS_OBJECT_NAME, literalFactory
                            .createTypedLiteral(name)));
                }

                // check children and add child and parent annotations
                checkChildren(subject, processedURIs, graph);
View Full Code Here

        RDFBridgeHelper.addPathAnnotations(cmsPath, processedURIs, graph);
        return graph;
    }

    private void checkChildren(NonLiteral objectURI, List<NonLiteral> processedURIs, MGraph graph) {
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        for (UriRef childPropURI : targetChildrenMappings.keySet()) {
            Iterator<Triple> childrenIt = graph.filter(objectURI, childPropURI, null);
            Map<String,Integer> childNames = new HashMap<String,Integer>();
            while (childrenIt.hasNext()) {
                Triple child = childrenIt.next();
                NonLiteral childSubject = new UriRef(RDFBridgeHelper.removeEndCharacters(child.getObject()
                        .toString()));

                String childName = getChildName(childSubject, targetChildrenMappings.get(childPropURI), graph);
                if (!childName.contentEquals("")) {
                    RDFBridgeHelper.removeExistingTriple(childSubject, CMSAdapterVocabulary.CMS_OBJECT_NAME,
                        graph);
                    graph.add(new TripleImpl(childSubject, RDFBridgeHelper.RDF_TYPE,
                            CMSAdapterVocabulary.CMS_OBJECT));
                    graph.add(new TripleImpl(childSubject, CMSAdapterVocabulary.CMS_OBJECT_PARENT_REF,
                            objectURI));
                    graph.add(new TripleImpl(childSubject, CMSAdapterVocabulary.CMS_OBJECT_NAME,
                            literalFactory.createTypedLiteral(checkDuplicateChildName(childName, childNames))));

                } else {
                    log.warn("Failed to obtain a name for child property: {}", childPropURI);
                }
            }
View Full Code Here

TOP

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

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.