当前位置: 首页>>代码示例>>Java>>正文


Java PlainLiteral类代码示例

本文整理汇总了Java中org.apache.clerezza.rdf.core.PlainLiteral的典型用法代码示例。如果您正苦于以下问题:Java PlainLiteral类的具体用法?Java PlainLiteral怎么用?Java PlainLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PlainLiteral类属于org.apache.clerezza.rdf.core包,在下文中一共展示了PlainLiteral类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleStatement

import org.apache.clerezza.rdf.core.PlainLiteral; //导入依赖的package包/类
private void handleStatement(RDFDataset result, Triple t, Map<BNode, String> bNodeMap) {
    final String subject = getResourceValue(t.getSubject(), bNodeMap);
    final String predicate = getResourceValue(t.getPredicate(), bNodeMap);
    final Resource object = t.getObject();

    if (object instanceof Literal) {

        final String value = ((Literal) object).getLexicalForm();
        final String language;
        final String datatype;
        if (object instanceof TypedLiteral) {
            language = null;
            datatype = getResourceValue(((TypedLiteral) object).getDataType(), bNodeMap);
        } else if (object instanceof PlainLiteral) {
            // we use RDF 1.1 literals so we do set the RDF_LANG_STRING
            // datatype
            datatype = RDF_LANG_STRING;
            final Language l = ((PlainLiteral) object).getLanguage();
            if (l == null) {
                language = null;
            } else {
                language = l.toString();
            }
        } else {
            throw new IllegalStateException("Unknown Literal class "
                    + object.getClass().getName());
        }
        result.addTriple(subject, predicate, value, datatype, language);
        count++;
    } else {
        result.addTriple(subject, predicate, getResourceValue((NonLiteral) object, bNodeMap));
        count++;
    }

}
 
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:36,代码来源:ClerezzaRDFParser.java

示例2: assertOASelector

import org.apache.clerezza.rdf.core.PlainLiteral; //导入依赖的package包/类
private void assertOASelector(ContentItem contentItem, UriRef selector){
    TripleCollection graph = contentItem.getMetadata();
    Set<UriRef> types = assertHasValues(graph, selector, RDF_TYPE, UriRef.class);
    assertTrue(types.contains(OA_TEXT_POSITION_SELECTOR));
    assertTrue(types.contains(OA_TEXT_QUOTE_SELECTOR));
    
    TypedLiteral startIndex = assertSingleValue(graph, selector, OA_START, TypedLiteral.class);
    assertEquals(XSD.int_, startIndex.getDataType());
    int start = lf.createObject(Integer.class, startIndex);
    TypedLiteral endIndex = assertSingleValue(graph, selector, OA_END, TypedLiteral.class);
    assertEquals(XSD.int_, endIndex.getDataType());
    int end = lf.createObject(Integer.class, endIndex);
    assertTrue(end > start);
    
    //assert the selector URI
    assertSelectorUri(contentItem, selector, start, end);

    PlainLiteral exact = assertSingleValue(graph, selector, OA_EXACT, PlainLiteral.class);
    if(exact != null){
        assertEquals(CONTENT_LANGUAGE, exact.getLanguage());
        assertEquals(CONTENT.substring(start,end), exact.getLexicalForm());
    }
    PlainLiteral prefix = assertSingleValue(graph, selector, OA_PREFIX, PlainLiteral.class);
    if(prefix != null){
        assertEquals(CONTENT_LANGUAGE, prefix.getLanguage());
        assertTrue(CONTENT.substring(0,start).endsWith(prefix.getLexicalForm()));
    }
    
    PlainLiteral suffix = assertSingleValue(graph, selector, OA_SUFIX, PlainLiteral.class);
    if(suffix != null){
        assertNotNull("if oa:suffix is present also oa:prefix is expected!",prefix);
        assertEquals(CONTENT_LANGUAGE, suffix.getLanguage());
        assertTrue(CONTENT.substring(end,CONTENT.length()).startsWith(suffix.getLexicalForm()));
    } else {
        assertNull("if oa:prefix is present als oa:suffix is expected!",prefix);
    }
    
}
 
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:39,代码来源:Fise2FamEngineTest.java

示例3: assertNifSelector

import org.apache.clerezza.rdf.core.PlainLiteral; //导入依赖的package包/类
private void assertNifSelector(ContentItem contentItem, UriRef selector){
        TripleCollection graph = contentItem.getMetadata();
        //assert the types
        Set<UriRef> types = assertHasValues(graph, selector, RDF_TYPE, UriRef.class);
        assertTrue(types.contains(NIF_STRING));
        assertTrue(types.contains(NIF_RFC5147STRING));
        
        //assert begin/end
        TypedLiteral beginIndex = assertSingleValue(graph, selector, NIF_BEGIN_INDEX, TypedLiteral.class);
        assertEquals(XSD.int_, beginIndex.getDataType());
        int begin = lf.createObject(Integer.class, beginIndex);
        TypedLiteral endIndex = assertSingleValue(graph, selector, NIF_END_INDEX, TypedLiteral.class);
        assertEquals(XSD.int_, endIndex.getDataType());
        int end = lf.createObject(Integer.class, endIndex);
        assertTrue(end > begin);
        
        //assert the selector URI
        assertSelectorUri(contentItem, selector, begin, end);
        
        //assert anchor OR head/tail
        PlainLiteral anchor = assertOptValue(graph, selector, NIF_ANCHOR_OF, PlainLiteral.class);
        if(anchor != null){
            assertEquals(CONTENT_LANGUAGE, anchor.getLanguage());
            assertEquals(CONTENT.substring(begin,end), anchor.getLexicalForm());
        }
        PlainLiteral head = assertOptValue(graph, selector, NIF_HEAD, PlainLiteral.class);
        if(head != null){
            assertEquals(CONTENT_LANGUAGE, head.getLanguage());
            assertTrue(CONTENT.substring(begin,end).startsWith(head.getLexicalForm()));
        } else {
//TODO            assertNotNull("If no nif:anchor is presnet nif:head AND nif:tail MUST BE defined (selector: "+ selector +")!", anchor);
        }
        PlainLiteral tail = assertOptValue(graph, selector, NIF_TAIL, PlainLiteral.class);
        if(tail != null){
            assertNotNull("if nif:tail is present also nif:head is expected!",head);
            assertEquals(CONTENT_LANGUAGE, tail.getLanguage());
            assertTrue(CONTENT.substring(end,CONTENT.length()).startsWith(tail.getLexicalForm()));
        } else {
            assertNull("if nif:head is present als nif:tail is expected!",head);
        }
        
        //assert before/after
        PlainLiteral before = assertOptValue(graph, selector, NIF_BEFORE, PlainLiteral.class);
        if(before != null){
            assertEquals(CONTENT_LANGUAGE, before.getLanguage());
            assertTrue(CONTENT.substring(0,begin).endsWith(before.getLexicalForm()));
        }
        PlainLiteral after = assertOptValue(graph, selector, NIF_AFTER, PlainLiteral.class);
        if(after != null){
            assertNotNull("if nif:after is present also nif:before is expected!",before);
            assertEquals(CONTENT_LANGUAGE, after.getLanguage());
            assertTrue(CONTENT.substring(end,CONTENT.length()).startsWith(after.getLexicalForm()));
        } else {
            assertNull("if nif:before is present als nif:after is expected!",before);
        }
        
        //assert the context
        UriRef context = assertSingleValue(graph, selector, NIF_REFERENCE_CONTEXT, UriRef.class);
        Set<UriRef> cTypes = assertHasValues(graph, context, RDF_TYPE, UriRef.class);
        assertTrue(cTypes.contains(NIF_CONTEXT));
        assertTrue(cTypes.contains(NIF_RFC5147STRING));
        UriRef sourceURL = assertSingleValue(graph, context, NIF_SOURCE_URL, UriRef.class);
        assertEquals(contentItem.getUri(), sourceURL);
        PlainLiteral isString = assertOptValue(graph, context, NIF_IS_STRING, PlainLiteral.class);
        if(isString != null){
            assertEquals(CONTENT_LANGUAGE, isString.getLanguage());
            assertEquals(CONTENT, isString.getLexicalForm());
        }
    }
 
开发者ID:fusepoolP3,项目名称:p3-stanbol-engine-fam,代码行数:70,代码来源:Fise2FamEngineTest.java

示例4: readDictionary

import org.apache.clerezza.rdf.core.PlainLiteral; //导入依赖的package包/类
public static DictionaryStore readDictionary(InputStream inputStream) {
    Triple triple;
    Resource resource;
    String label, lang;

    DictionaryStore dictionary = new DictionaryStore();
    MGraph graph = new IndexedMGraph();
    Parser.getInstance().parse(graph, inputStream, "application/rdf+xml");
    Iterator<Triple> typeTriples = graph.filter(null, RDF.type, SKOS04.Concept);
    while (typeTriples.hasNext()) {
        NonLiteral s = typeTriples.next().getSubject();
        if (s instanceof UriRef) {
            UriRef concept = (UriRef) s;

            // getting prefLabels
            Iterator<Triple> prefTriples = graph.filter(concept, SKOS04.prefLabel, null);
            while (prefTriples.hasNext()) {
                triple = prefTriples.next();
                resource = triple.getObject();
                if (resource instanceof PlainLiteral) {
                    label = ((PlainLiteral) resource).getLexicalForm();
                    lang = ((PlainLiteral) resource).getLanguage() == null ? null : ((PlainLiteral) resource).getLanguage().toString();
                } else if (resource instanceof TypedLiteral && ((TypedLiteral) resource).getDataType().equals(XSD.string)) {
                    label = ((Literal) resource).getLexicalForm();
                    lang = null;
                } else {
                    label = null;
                    lang = null;
                }

                if (StringUtils.isNotBlank(label) && StringUtils.isNotBlank(concept.getUnicodeString())) {
                    dictionary.addOriginalElement(label, SKOS04.prefLabel, concept.getUnicodeString());
                }
            }

            // getting altLabels
            Iterator<Triple> altTriples = graph.filter(concept, SKOS04.altLabel, null);
            while (altTriples.hasNext()) {
                triple = altTriples.next();
                resource = triple.getObject();
                if (resource instanceof PlainLiteral) {
                    label = ((PlainLiteral) resource).getLexicalForm();
                    lang = ((PlainLiteral) resource).getLanguage() == null ? null : ((PlainLiteral) resource).getLanguage().toString();
                } else if (resource instanceof TypedLiteral && ((TypedLiteral) resource).getDataType().equals(XSD.string)) {
                    label = ((Literal) resource).getLexicalForm();
                    lang = null;
                } else {
                    label = null;
                    lang = null;
                }

                if (StringUtils.isNotBlank(label) && StringUtils.isNotBlank(concept.getUnicodeString())) {
                    dictionary.addOriginalElement(label, SKOS04.altLabel, concept.getUnicodeString());
                }
            }

        }
    }
    return dictionary;
}
 
开发者ID:fusepoolP3,项目名称:p3-dictionary-matcher-transformer,代码行数:61,代码来源:Reader.java


注:本文中的org.apache.clerezza.rdf.core.PlainLiteral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。