Package org.apache.clerezza.rdf.core

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


     * @see EnhancementEngineHelper#createTextEnhancement(ContentItem, EnhancementEngine)
     */
    @Deprecated
    public static UriRef createNewExtraction(ContentItem ci,
            EnhancementEngine engine) {
        LiteralFactory literalFactory = LiteralFactory.getInstance();

        MGraph metadata = ci.getMetadata();
        UriRef extraction = new UriRef("urn:extraction-"
                + EnhancementEngineHelper.randomUUID());

        metadata.add(new TripleImpl(extraction, Properties.RDF_TYPE,
                TechnicalClasses.ENHANCER_EXTRACTION));

        // relate the extraction to the content item
        metadata.add(new TripleImpl(extraction,
                Properties.ENHANCER_RELATED_CONTENT_ITEM, new UriRef(ci.getUri().getUnicodeString())));

        // creation date
        metadata.add(new TripleImpl(extraction, Properties.DC_CREATED,
                literalFactory.createTypedLiteral(new Date())));

        // the engines that extracted the data
        // TODO: add some kind of versioning info for the extractor?
        // TODO: use a public dereferencing URI instead? that would allow for
        // explicit versioning too
        metadata.add(new TripleImpl(extraction, Properties.DC_CREATOR,
                literalFactory.createTypedLiteral(engine.getClass().getName())));

        return extraction;
    }
View Full Code Here


            }
        } else { // null indicates to use the Entityhub to lookup Entities
            site = null;
        }
        MGraph graph = ci.getMetadata();
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        // Retrieve the existing text annotations (requires read lock)
        Map<NamedEntity,List<UriRef>> textAnnotations = new HashMap<NamedEntity,List<UriRef>>();
        ci.getLock().readLock().lock();
        try {
            for (Iterator<Triple> it = graph.filter(null, RDF_TYPE, TechnicalClasses.ENHANCER_TEXTANNOTATION); it
View Full Code Here

                new Mapping.Converter(){//we need to convert from MByte/min to kByte/sec
                    @Override
                    public Resource convert(Resource value) {
                        if(value instanceof TypedLiteral &&
                                XSD.double_.equals(((TypedLiteral)value).getDataType())){
                            LiteralFactory lf = LiteralFactory.getInstance();
                            double mm = lf.createObject(Double.class, (TypedLiteral)value);
                            return lf.createTypedLiteral(Double.valueOf(
                                mm*1024/60));
                        } else {
                            return value; //do not convert
                        }
                    }
View Full Code Here

    private static void createGraph(TripleCollection tc, int triples, Long seed){
        Random rnd = new Random();
        if(seed != null){
             rnd.setSeed(seed);
        }
        LiteralFactory lf = LiteralFactory.getInstance();
        //randoms are in the range [0..3]
        double l = 1.0; //literal
        double i = l / 3; //int
        double d = l * 2 / 3;//double
        double b = 2.0;//bNode
        double nb = b - (l * 2 / 3); //create new bNode
        double random;
        NonLiteral subject = null;
        UriRef predicate = null;
        List<UriRef> predicateList = new ArrayList<UriRef>();
        predicateList.add(RDF.first);
        predicateList.add(RDF.rest);
        predicateList.add(RDF.type);
        predicateList.add(RDFS.label);
        predicateList.add(RDFS.comment);
        predicateList.add(RDFS.range);
        predicateList.add(RDFS.domain);
        predicateList.add(FOAF.name);
        predicateList.add(FOAF.nick);
        predicateList.add(FOAF.homepage);
        predicateList.add(FOAF.age);
        predicateList.add(FOAF.depiction);
        String URI_PREFIX = "http://www.test.org/bigGraph/ref";
        Language DE = new Language("de");
        Language EN = new Language("en");
        Iterator<UriRef> predicates = predicateList.iterator();
        List<BNode> bNodes = new ArrayList<BNode>();
        bNodes.add(new BNode());
        for (int count = 0; tc.size() < triples; count++) {
            random = rnd.nextDouble() * 3;
            if (random >= 2.5 || count == 0) {
                if (random <= 2.75) {
                    subject = new UriRef(URI_PREFIX + count);
                } else {
                    int rndIndex = (int) ((random - 2.75) * bNodes.size() / (3.0 - 2.75));
                    subject = bNodes.get(rndIndex);
                }
            }
            if (random > 2.0 || count == 0) {
                if (!predicates.hasNext()) {
                    Collections.shuffle(predicateList);
                    predicates = predicateList.iterator();
                }
                predicate = predicates.next();
            }
            if (random <= l) { //literal
                if (random <= i) {
                    tc.add(new TripleImpl(subject, predicate, lf.createTypedLiteral(count)));
                } else if (random <= d) {
                    tc.add(new TripleImpl(subject, predicate, lf.createTypedLiteral(random)));
                } else {
                    PlainLiteral text;
                    if (random <= i) {
                        text = new PlainLiteralImpl("Literal for " + count);
                    } else if (random <= d) {
View Full Code Here

    @Override
    public void computeEnhancements(ContentItem ci) throws EngineException {
        UriRef contentItemId = ci.getUri();
        MGraph graph = ci.getMetadata();
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        //get all the textAnnotations
        /*
         * this Map holds the name as key and all the text annotations of
         * dc:type dbpedia:Place that select this name as value
         * this map is used to avoid multiple lookups for text annotations
View Full Code Here

    //add the language of the text
    ci.getMetadata().add(new TripleImpl(ci.getUri(), Properties.DC_LANGUAGE,
        new PlainLiteralImpl("en")));
    assertEquals("en", EnhancementEngineHelper.getLanguage(ci));
   
    LiteralFactory lf = LiteralFactory.getInstance();

    //we need also to create a fise:TextAnnotation to test disambiguation
    String selected = "Angela Merkel";
    Language en = new Language("en");
    UriRef textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci,
        new DBPSpotlightSpotEnhancementEngine());
    MGraph model = ci.getMetadata();
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_SELECTED_TEXT,
        new PlainLiteralImpl(selected,en)));
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_SELECTION_CONTEXT,
        new PlainLiteralImpl(TEST_TEXT,en)));
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_START,
        lf.createTypedLiteral(TEST_TEXT.indexOf(selected))));
    model.add(new TripleImpl(textAnnotation, Properties.ENHANCER_END,
        lf.createTypedLiteral(TEST_TEXT.indexOf(selected)+selected.length())));
    model.add(new TripleImpl(textAnnotation, Properties.DC_TYPE,
        OntologicalClasses.DBPEDIA_PERSON));
    //validate that the created TextAnnotation is valid (test the test ...)
    EnhancementStructureHelper.validateAllTextAnnotations(model, TEST_TEXT, null);
  }
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<NamedEntity> lista = this.client.extractEntities(text, language);
      LiteralFactory literalFactory = LiteralFactory.getInstance();

      MGraph g = ci.getMetadata();

      for (NamedEntity ne : 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(ne.getFormKind(),lang)));
          g.add(new TripleImpl(textAnnotation, DC_TYPE, getEntityRefForType(ne.type)));
          if (ne.getFrom() != null && ne.getTo() != null) {
            g.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory.createTypedLiteral(
                ne.getFrom().intValue())));
            g.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory.createTypedLiteral(
                ne.getTo().intValue())));
            g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTION_CONTEXT,
                new PlainLiteralImpl(getSelectionContext(text, ne.getFormKind(), ne.getFrom().intValue()), lang)));
          }
        } catch (NoConvertorException e) {
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.