Package org.apache.clerezza.rdf.core

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


        }
        Literal literal;
        if (label.getLanguage() == null) {
            literal = new PlainLiteralImpl(label.getText());
        } else {
            literal = new PlainLiteralImpl(label.getText(), new Language(label.getLanguage()));
        }
        // Now create the entityAnnotation
        UriRef entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(graph, engine,
            contentItemId);
        // first relate this entity annotation to the text annotation(s)
View Full Code Here


     * @param ci
     * @param linkedEntities
     * @param language
     */
    private void writeEnhancements(ContentItem ci, Collection<LinkedEntity> linkedEntities, String language) {
        Language languageObject = null;
        if(language != null && !language.isEmpty()){
            languageObject = new Language(language);
        }
        MGraph metadata = ci.getMetadata();
        for(LinkedEntity linkedEntity : linkedEntities){
            Collection<UriRef> textAnnotations = new ArrayList<UriRef>(linkedEntity.getOccurrences().size());
            //first create the TextAnnotations for the Occurrences
            for(Occurrence occurrence : linkedEntity.getOccurrences()){
                UriRef textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
                textAnnotations.add(textAnnotation);
                metadata.add(new TripleImpl(textAnnotation,
                    Properties.ENHANCER_START,
                    literalFactory.createTypedLiteral(occurrence.getStart())));
                metadata.add(new TripleImpl(textAnnotation,
                    Properties.ENHANCER_END,
                    literalFactory.createTypedLiteral(occurrence.getEnd())));
                metadata.add(new TripleImpl(textAnnotation,
                    Properties.ENHANCER_SELECTION_CONTEXT,
                    new PlainLiteralImpl(occurrence.getContext(),languageObject)));
                metadata.add(new TripleImpl(textAnnotation,
                    Properties.ENHANCER_SELECTED_TEXT,
                    new PlainLiteralImpl(occurrence.getSelectedText(),languageObject)));
                metadata.add(new TripleImpl(textAnnotation,
                    Properties.ENHANCER_CONFIDENCE,
                    literalFactory.createTypedLiteral(linkedEntity.getScore())));
                for(UriRef dcType : linkedEntity.getTypes()){
                    metadata.add(new TripleImpl(
                        textAnnotation, Properties.DC_TYPE, dcType));
                }
            }
            //now the EntityAnnotations for the Suggestions
            for(Suggestion suggestion : linkedEntity.getSuggestions()){
                UriRef entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(ci, this);
                //should we use the label used for the match, or search the
                //representation for the best label ... currently its the matched one
                Text label = suggestion.getBestLabel(linkerConfig.getNameField(),language);
                metadata.add(new TripleImpl(entityAnnotation,
                    Properties.ENHANCER_ENTITY_LABEL,
                    label.getLanguage() == null ?
                            new PlainLiteralImpl(label.getText()) :
                                new PlainLiteralImpl(label.getText(),
                                    new Language(label.getLanguage()))));
                metadata.add(new TripleImpl(entityAnnotation,
                    Properties.ENHANCER_ENTITY_REFERENCE,
                    new UriRef(suggestion.getRepresentation().getId())));
                Iterator<Reference> suggestionTypes = suggestion.getRepresentation().getReferences(linkerConfig.getTypeField());
                while(suggestionTypes.hasNext()){
View Full Code Here

        }
        Literal literal;
        if (label.getLanguage() == null) {
            literal = new PlainLiteralImpl(label.getText());
        } else {
            literal = new PlainLiteralImpl(label.getText(), new Language(label.getLanguage()));
        }
        // Now create the entityAnnotation
        UriRef entityAnnotation = EnhancementEngineHelper.createEntityEnhancement(graph, engine,
            contentItemId);
        // first relate this entity annotation to the text annotation(s)
View Full Code Here

        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;
 
View Full Code Here

            new Object[] {content, language, type});
        if (type == null) {
            if(language == null){
                return new PlainLiteralImpl(content);
            } else {
                return new PlainLiteralImpl(content, new Language(language.getLanguage()));
            }
        } else {
            return new TypedLiteralImpl(content, XSD.getXsdUriRef(type));
        }
    }
View Full Code Here

    }

    @Override
    public Locale getLiteralLanguage(Resource resource) {
        if (resource instanceof PlainLiteral) {
            Language lang = ((PlainLiteral) resource).getLanguage();
            return lang != null ? new Locale(lang.toString()) : null;
        } else {
            throw new IllegalArgumentException("Resource " + resource.toString() + " is not a PlainLiteral");
        }
    }
View Full Code Here

            String graph) {
        final NonLiteral subject = getNonLiteral(s);
        final UriRef predicate = new UriRef(p);
        Resource object;
        if (language != null) {
            object = new PlainLiteralImpl(value, new Language(language));
        } else {
            if (datatype != null) {
                object = new TypedLiteralImpl(value, new UriRef(datatype));
            } else {
                object = new PlainLiteralImpl(value);
View Full Code Here

                    .getDataType().getUnicodeString()));
        } else if (resource instanceof PlainLiteral) {
            value = doc.createElement("literal");
            value.appendChild(doc.createTextNode(((PlainLiteral) resource)
                    .getLexicalForm()));
            Language lang = ((PlainLiteral) resource).getLanguage();
            if (lang != null) {
                value.setAttribute("xml:lang", (lang.toString()));
            }
        } else {
            value = doc.createElement("bnode");
            value.appendChild(doc.createTextNode(((BNode) resource).toString()));
        }
View Full Code Here

        Assert.assertFalse(literal1.equals(literal3));
    }
   
    @Test public void languageLiteralEquality() {
        String stringValue = "some text";
        Language lang = new Language("en-ca");
        PlainLiteral literal1 = new PlainLiteralImpl(stringValue, lang);
        PlainLiteral literal2 = new PlainLiteralImpl(stringValue, lang);       
        Assert.assertEquals(literal1, literal2);
        Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
        Language lang2 = new Language("de");
        PlainLiteral literal3 = new PlainLiteralImpl(stringValue, lang2);
        Assert.assertFalse(literal1.equals(literal3));
        PlainLiteral literal4 = new PlainLiteralImpl(stringValue, null);
        Assert.assertFalse(literal3.equals(literal4));
        Assert.assertFalse(literal4.equals(literal3));
View Full Code Here

    /**
     * hashCode of the lexical form plus the hashCode of the locale
     */
    @Test public void checkHashCode() {
        String stringValue = "some text";
        Language language = new Language("en");
        PlainLiteral literal = new PlainLiteralImpl(stringValue, language);
        Assert.assertEquals(stringValue.hashCode() + language.hashCode(), literal.hashCode());
    }
View Full Code Here

TOP

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

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.