本文整理汇总了Java中org.apache.clerezza.rdf.core.TypedLiteral类的典型用法代码示例。如果您正苦于以下问题:Java TypedLiteral类的具体用法?Java TypedLiteral怎么用?Java TypedLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypedLiteral类属于org.apache.clerezza.rdf.core包,在下文中一共展示了TypedLiteral类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPoint
import org.apache.clerezza.rdf.core.TypedLiteral; //导入依赖的package包/类
/**
* Extracts one spatial point or event from the client data.
* @param graph
* @return
* @throws ParseException
*/
public WGS84Point getPoint(TripleCollection graph) {
WGS84Point point = new WGS84Point();
NonLiteral pointRef = graph.filter(null, geo_lat, null).next().getSubject();
String latitude = ( (TypedLiteral) graph.filter(pointRef, geo_lat, null).next().getObject() ).getLexicalForm();
String longitude = ( (TypedLiteral) graph.filter(pointRef, geo_long, null).next().getObject() ).getLexicalForm();
point.setUri(pointRef.toString());
point.setLat(Double.valueOf(latitude));
point.setLong(Double.valueOf(longitude));
// look for events linked to places
if(graph.filter(null, schema_startDate, null).hasNext()){
String startDate = ( (TypedLiteral) graph.filter(null, schema_startDate, null).next().getObject()).getLexicalForm();
String endDate = ( (TypedLiteral) graph.filter(null, schema_endDate, null).next().getObject()).getLexicalForm();
point.setStartDate(startDate);
point.setEndDate(endDate);
}
return point;
}
示例2: handleStatement
import org.apache.clerezza.rdf.core.TypedLiteral; //导入依赖的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++;
}
}
示例3: assertOASelector
import org.apache.clerezza.rdf.core.TypedLiteral; //导入依赖的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);
}
}
示例4: addSubjects
import org.apache.clerezza.rdf.core.TypedLiteral; //导入依赖的package包/类
/**
* Add dc:subject property to items pointing to entities extracted by NLP
* engines in the default chain. Given a node and a TripleCollection
* containing fise:Enhancements about that node dc:subject properties are
* added to an item pointing to entities referenced by those enhancements if
* the enhancement confidence value is above a threshold.
*
* @param node
* @param metadata
*/
private void addSubjects(MGraph targetGraph, UriRef itemRef, TripleCollection metadata) {
final GraphNode enhancementType = new GraphNode(TechnicalClasses.ENHANCER_ENHANCEMENT, metadata);
final Set<UriRef> entities = new HashSet<UriRef>();
// get all the enhancements
final Iterator<GraphNode> enhancements = enhancementType.getSubjectNodes(RDF.type);
while (enhancements.hasNext()) {
final GraphNode enhhancement = enhancements.next();
final Iterator<Literal> confidenceLiterals = enhhancement.getLiterals(org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_CONFIDENCE);
//look the confidence value for each enhancement
double enhancementConfidence = confidenceLiterals.hasNext() ?
LiteralFactory.getInstance().createObject(Double.class,
(TypedLiteral) confidenceLiterals.next()) : 1;
if (enhancementConfidence >= confidenceThreshold) {
// get entities referenced in the enhancement
final Iterator<Resource> referencedEntities = enhhancement.getObjects(org.apache.stanbol.enhancer.servicesapi.rdf.Properties.ENHANCER_ENTITY_REFERENCE);
while (referencedEntities.hasNext()) {
final UriRef entity = (UriRef) referencedEntities.next();
// Add dc:subject to the patent for each referenced entity
targetGraph.add(new TripleImpl(itemRef, DC.subject, entity));
entities.add(entity);
}
}
}
for (UriRef uriRef : entities) {
// We don't get the entity description directly from metadata
// as the context there would include
addResourceDescription(uriRef, targetGraph);
}
}
示例5: assertNifSelector
import org.apache.clerezza.rdf.core.TypedLiteral; //导入依赖的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());
}
}
示例6: readDictionary
import org.apache.clerezza.rdf.core.TypedLiteral; //导入依赖的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;
}