Search in sources :

Example 91 with IRI

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));
            }
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ServiceReference(org.osgi.framework.ServiceReference)

Example 92 with IRI

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;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 93 with IRI

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;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Language(org.apache.clerezza.commons.rdf.Language) Element(org.w3c.dom.Element) Literal(org.apache.clerezza.commons.rdf.Literal)

Example 94 with IRI

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);
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Blob(org.apache.stanbol.enhancer.servicesapi.Blob) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) IOException(java.io.IOException) InvalidContentException(org.apache.stanbol.enhancer.servicesapi.InvalidContentException) Graph(org.apache.clerezza.commons.rdf.Graph) SOAPException(javax.xml.soap.SOAPException) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)

Example 95 with IRI

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();
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) XMPPacketScanner(org.apache.tika.parser.image.xmp.XMPPacketScanner) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)346 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)113 Graph (org.apache.clerezza.commons.rdf.Graph)109 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)104 Triple (org.apache.clerezza.commons.rdf.Triple)88 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)84 Test (org.junit.Test)78 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)58 HashSet (java.util.HashSet)50 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)46 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)37 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)36 Literal (org.apache.clerezza.commons.rdf.Literal)35 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)31 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)29 Recipe (org.apache.stanbol.rules.base.api.Recipe)29 Language (org.apache.clerezza.commons.rdf.Language)24