use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class SparqlEndpointResource method populateGraphList.
private void populateGraphList(Map<ServiceReference, Graph> services) {
if (services != null) {
for (ServiceReference service : services.keySet()) {
Object graphUri = service.getProperty(GRAPH_URI);
if (service.getProperty(GRAPH_URI) instanceof IRI) {
graphUri = ((IRI) graphUri).getUnicodeString();
}
Object graphName = service.getProperty("graph.name");
Object graphDescription = service.getProperty("graph.description");
if (graphUri instanceof String && graphName instanceof String && graphDescription instanceof String) {
tripleCollections.add(new GraphInfo((String) graphUri, (String) graphName, (String) graphDescription));
}
}
}
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class RdfSerializingWriter method getObjectExpansionProperties.
private Set<IRI> getObjectExpansionProperties(GraphNode recipe) {
final MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(true);
final List<String> paramValues = queryParams.get(OBJ_EXP_PARAM);
final Set<IRI> result = new HashSet<IRI>();
if (paramValues != null) {
for (String uriString : paramValues) {
result.add(new IRI(uriString));
}
}
if (recipe != null) {
Iterator<GraphNode> ingredients = recipe.getObjectNodes(RECIPES.ingredient);
while (ingredients.hasNext()) {
Iterator<RDFTerm> properties = ingredients.next().getObjects(RECIPES.ingredientProperty);
while (properties.hasNext()) {
result.add((IRI) properties.next());
}
}
}
return result;
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class ResultSetToXml method createValueElement.
private Element createValueElement(RDFTerm resource, Document doc) {
Element value;
if (resource instanceof IRI) {
value = doc.createElement("uri");
value.appendChild(doc.createTextNode(((IRI) resource).getUnicodeString()));
} else if (resource instanceof Literal) {
value = doc.createElement("literal");
value.appendChild(doc.createTextNode(((Literal) resource).getLexicalForm()));
value.setAttribute("datatype", (((Literal) resource).getDataType().getUnicodeString()));
Language lang = ((Literal) resource).getLanguage();
if (lang != null) {
value.setAttribute("xml:lang", (lang.toString()));
}
} else {
value = doc.createElement("bnode");
value.appendChild(doc.createTextNode(resource.toString()));
}
return value;
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class CeliLanguageIdentifierEnhancementEngine method computeEnhancements.
@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
Entry<IRI, Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMTYPES);
if (contentPart == null) {
throw new IllegalStateException("No ContentPart with Mimetype '" + TEXT_PLAIN_MIMETYPE + "' found for ContentItem " + ci.getUri() + ": This is also checked in the canEnhance method! -> This " + "indicated an Bug in the implementation of the " + "EnhancementJobManager!");
}
String text = "";
try {
text = ContentItemHelper.getText(contentPart.getValue());
} catch (IOException e) {
throw new InvalidContentException(this, ci, e);
}
if (text.trim().length() == 0) {
log.info("No text contained in ContentPart {" + contentPart.getKey() + "} of ContentItem {" + ci.getUri() + "}");
return;
}
try {
String[] tmps = text.split(" ");
List<GuessedLanguage> lista = null;
if (tmps.length > 5)
lista = this.client.guessLanguage(text);
else
lista = this.client.guessQueryLanguage(text);
Graph g = ci.getMetadata();
// in ENHANCE_ASYNC we need to use read/write locks on the ContentItem
ci.getLock().writeLock().lock();
try {
GuessedLanguage gl = lista.get(0);
IRI textEnhancement = EnhancementEngineHelper.createTextEnhancement(ci, this);
g.add(new TripleImpl(textEnhancement, DC_LANGUAGE, new PlainLiteralImpl(gl.getLang())));
g.add(new TripleImpl(textEnhancement, ENHANCER_CONFIDENCE, literalFactory.createTypedLiteral(gl.getConfidence())));
g.add(new TripleImpl(textEnhancement, DC_TYPE, DCTERMS_LINGUISTIC_SYSTEM));
} finally {
ci.getLock().writeLock().unlock();
}
} catch (IOException e) {
throw new EngineException("Error while calling the CELI language" + " identifier service (configured URL: " + serviceURL + ")!", e);
} catch (SOAPException e) {
throw new EngineException("Error wile encoding/decoding the request/" + "response to the CELI language identifier service!", e);
}
}
use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.
the class XmpExtractorEngine method computeEnhancements.
@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
InputStream in = ci.getBlob().getStream();
XMPPacketScanner scanner = new XMPPacketScanner();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
scanner.parse(in, baos);
} catch (IOException e) {
throw new EngineException(e);
}
byte[] bytes = baos.toByteArray();
if (bytes.length > 0) {
Graph model = new IndexedGraph();
parser.parse(model, new ByteArrayInputStream(bytes), "application/rdf+xml");
GraphNode gn = new GraphNode(new IRI("http://relative-uri.fake/"), model);
gn.replaceWith(ci.getUri());
ci.getLock().writeLock().lock();
try {
LOG.info("Model: {}", model);
ci.getMetadata().addAll(model);
} finally {
ci.getLock().writeLock().unlock();
}
}
}
Aggregations