Package org.apache.clerezza.rdf.core

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


        public String getSummary() {
            Iterator<Triple> abstracts = entityProperties.filter(uri, SUMMARY, null);
            while (abstracts.hasNext()) {
                Resource object = abstracts.next().getObject();
                if (object instanceof PlainLiteral) {
                    PlainLiteral abstract_ = (PlainLiteral) object;
                    if (new Language("en").equals(abstract_.getLanguage())) {
                        return abstract_.getLexicalForm();
                    }
                }
            }
            return "";
        }
View Full Code Here


   
    public void addEntity(Entity rep){
        entities.put(rep.getUri(), rep);
        Iterator<PlainLiteral> labels = rep.getText(nameField);
        while(labels.hasNext()){
            PlainLiteral label = labels.next();
            for(String token : tokenizer.tokenize(label.getLexicalForm(),null)){
                Collection<Entity> values = data.get(token);
                if(values == null){
                    values = new ArrayList<Entity>();
                    data.put(label.getLexicalForm(), values);
                }
                values.add(rep);
            }
        }
       
View Full Code Here

            //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
                PlainLiteral label = suggestion.getBestLabel(linkerConfig.getNameField(),language);
                Entity entity = suggestion.getEntity();
                metadata.add(new TripleImpl(entityAnnotation, Properties.ENHANCER_ENTITY_LABEL, label));
                metadata.add(new TripleImpl(entityAnnotation,ENHANCER_ENTITY_REFERENCE, entity.getUri()));
                Iterator<UriRef> suggestionTypes = entity.getReferences(linkerConfig.getTypeField());
                while(suggestionTypes.hasNext()){
View Full Code Here

     */
    public PlainLiteral getBestLabel(UriRef nameField, String language){
        Entity rep = getEntity();
        //start with the matched label -> so if we do not find a better one
        //we will use the matched!
        PlainLiteral matchedLabel = getMatchedLabel();
        PlainLiteral label = matchedLabel;
        // 1. check if the returned Entity does has a label -> if not return null
        // add labels (set only a single label. Use "en" if available!
        Iterator<PlainLiteral> labels = rep.getText(nameField);
        boolean matchFound = false;
        while (labels.hasNext() && !matchFound) {
            PlainLiteral actLabel = labels.next();
            if(label == null){
                label = actLabel;
            }
            //now we have already a label check the language
            Language actLang = actLabel.getLanguage();
            //use startWith to match also en-GB and en-US ...
            if (actLang != null && actLang.toString().startsWith(language)) {
                //prefer labels with the correct language
                label = actLabel;
                if(matchedLabel != null && matchedLabel.getLexicalForm().equalsIgnoreCase(label.getLexicalForm())){
View Full Code Here

        Collection<PlainLiteral> defaultLabels = new ArrayList<PlainLiteral>();
        boolean matchedLangLabel = false;
        //avoid matching multiple labels with the exact same lexical.
        Set<String> matchedLabels = new HashSet<String>();
        while(labels.hasNext()){
            PlainLiteral label = labels.next();
            //numLabels++;
            String lang = label.getLanguage() != null ? label.getLanguage().toString() : null;
            String text = label.getLexicalForm();
            //if case-insensitive matching ... compare lower case versions
            if(!linkerConfig.isCaseSensitiveMatching()){
                text = text.toLowerCase(Locale.ROOT);
            }
            if((lang == null && curLang == null) ||
View Full Code Here

            log.debug(" > register {}",entity);
        }
        entities.put(entity.getUri(), entity);
        Iterator<PlainLiteral> labels = entity.getText(nameField);
        while(labels.hasNext()){
            PlainLiteral label = labels.next();
            String lang = label.getLanguage() == null ? null : label.getLanguage().toString();
            if(indexLanguages.contains(lang)){
                for(String token : tokenizer.tokenize(label.getLexicalForm(),null)){
                    token = token.toLowerCase(Locale.ROOT);
                    Collection<Entity> values = index.get(token);
                    if(values == null){
                        values = new ArrayList<Entity>();
                        index.put(token, values);
View Full Code Here

        boolean containsNull = languageSet.contains(null);
        List<String> results = new ArrayList<String>();
        while (literals.hasNext()) {
            Literal act = literals.next();
            if (act instanceof PlainLiteral) {
                PlainLiteral pl = (PlainLiteral) act;
                if (languageSet.contains(pl.getLanguage())) {
                    results.add(0, pl.getLexicalForm()); //add to front
                }
            } else if (containsNull) { //add also all types Literals, because the do not define an language!
                results.add(act.getLexicalForm()); //append to the end
            }
        }
View Full Code Here

     * {@link Representation#get(String, String...)}).
     */
    @Test
    public void testPlainLiteralToTextConversion(){
        String field = "urn:test.RdfRepresentation:test.field";
        PlainLiteral noLangLiteral = new PlainLiteralImpl("A plain literal without Language");
        PlainLiteral enLiteral = new PlainLiteralImpl("An english literal",new Language("en"));
        PlainLiteral deLiteral = new PlainLiteralImpl("Ein Deutsches Literal",new Language("de"));
        PlainLiteral deATLiteral = new PlainLiteralImpl("Ein Topfen Verband hilft bei Zerrungen",new Language("de-AT"));
        Collection<PlainLiteral> plainLiterals = Arrays.asList(noLangLiteral,enLiteral,deLiteral,deATLiteral);
        Representation rep = createRepresentation(null);
        rep.add(field, plainLiterals);
        //now test, that the Plain Literals are available as natural language
        //tests via the Representation Interface!
View Full Code Here

                   
                    String strValue = currentTriple.getObject().toString();
                    JsonLdPropertyValue jldValue = new JsonLdPropertyValue();

                    if (currentTriple.getObject() instanceof PlainLiteral) {
                        PlainLiteral plain = (PlainLiteral) currentTriple.getObject();
                        if (plain.getLanguage() != null) {
                            jldValue.setLanguage(plain.getLanguage().toString());
                        }
                        strValue = plain.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof TypedLiteral) {
                        TypedLiteral typedObject = (TypedLiteral) currentTriple.getObject();
                        String type = typedObject.getDataType().getUnicodeString();
                        jldValue.setType(type);
View Full Code Here

                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) {
                        text = new PlainLiteralImpl("An English literal for " + count, EN);
                    } else {
View Full Code Here

TOP

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

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.