Package org.apache.stanbol.commons.indexedgraph

Examples of org.apache.stanbol.commons.indexedgraph.IndexedMGraph


    protected InMemoryContentItem(String uriString, Blob blob, MGraph metadata) {
        this(uriString != null ? new UriRef(uriString) : null, blob, metadata);
    }
    protected InMemoryContentItem(UriRef uri, Blob blob, MGraph metadata) {
        super(uri == null ? ContentItemHelper.makeDefaultUrn(blob): uri,blob,
                metadata == null ? new IndexedMGraph() : metadata);
    }
View Full Code Here


    protected class FileContentItem extends ContentItemImpl implements ContentItem {
       
        public FileContentItem(UriRef id, Blob blob,MGraph metadata) {
            super(id == null ? getDefaultUri(blob, DEFAULT_CONTENT_ITEM_PREFIX) : id, blob,
                    metadata == null ? new IndexedMGraph() : metadata);
        }
View Full Code Here

            super(id == null ? getDefaultUri(blob, DEFAULT_CONTENT_ITEM_PREFIX) : id, blob,
                    metadata == null ? new IndexedMGraph() : metadata);
        }
        public FileContentItem(String prefix, Blob blob,MGraph metadata) {
            super(getDefaultUri(blob, prefix), blob,
                metadata == null ? new IndexedMGraph() : metadata);
        }
View Full Code Here

     * @param parser
     * @return
     * @throws IOException
     */
    protected static MGraph parseRdfData(ParsingProvider parser,String name) throws IOException {
        MGraph rdfData = new IndexedMGraph();
        InputStream in = getTestResource(name);
        assertNotNull("File '"+name+"' not found",in);
        ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(in));
        InputStream uncloseable = new UncloseableStream(zipIn);
        ZipEntry entry;
        while((entry = zipIn.getNextEntry()) != null){
            if(entry.getName().endsWith(".rdf")){
                parser.parse(rdfData,uncloseable, SupportedFormat.RDF_XML,null);
            }
        }
        assertTrue(rdfData.size() > 0);
        zipIn.close();
        return rdfData;
    }
View Full Code Here

            uri = ContentItemHelper.makeDefaultUrn(content);
        } else {
            uri = new UriRef(id);
        }
        log.debug("Created ContentItem with id:{} and uri:{}", id, uri);
        final MGraph g = new IndexedMGraph();
        ContentItem ci = null;
        try {
            ci = ciFactory.createContentItem(uri, new ByteArraySource(content, contentType), g);
        } catch (IOException e) {
            log.error("Failed to create contentitem with uri: {}", uri.getUnicodeString());
View Full Code Here

            log.error(msg, e);
            throw new StoreException(msg, e);
        }

        ResultSet resultSet = tcManager.executeSparqlQuery(selectQuery, this.getEnhancementGraph());
        MGraph metadata = new IndexedMGraph();
        while (resultSet.hasNext()) {
            SolutionMapping mapping = resultSet.next();
            UriRef ref = (UriRef) mapping.get("enhID");
            Iterator<Triple> tripleItr = this.getEnhancementGraph().filter(ref, null, null);
            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                metadata.add(triple);
            }
        }
        ContentItem ci = null;
        try {
            ci = ciFactory
View Full Code Here

        String content = "The Stanbol Enhancer can extract Entities form parsed Text.";
        Language lang = new Language("en");
        int start = content.indexOf("Stanbol");
        int end = start+"Stanbol Enhancer".length();
        UriRef ciUri = new UriRef("http://www.example.org/contentItem#1");
        MGraph metadata = new IndexedMGraph();
        UriRef ta = EnhancementEngineHelper.createTextEnhancement(metadata, dummyEngine, ciUri);
        EnhancementEngineHelper.setOccurrence(metadata, ta, content, start, end, lang, -1, true);
        Assert.assertEquals("The ", EnhancementEngineHelper.getString(
            metadata, ta,Properties.ENHANCER_SELECTION_PREFIX));
        Assert.assertEquals("Stanbol Enhancer", EnhancementEngineHelper.getString(
View Full Code Here

            graph = tcProvider.createMGraph(name);
            bindPhysicalOrigin(Origin.create(name));
            // XXX if addition fails, should rollback procedures also delete the graph?
        } else {
            // In memory graph, will most likely have to be copied afterwards.
            graph = new IndexedMGraph();
            bindPhysicalOrigin(null);
        }

        Iterator<String> itf = formats.iterator();
        if (!itf.hasNext()) throw new OntologyLoadingException("No suitable format found or defined.");
View Full Code Here

    /**
     * @return an RDF/JSON descriptions of places for the word map widget
     */
    public String getPlacesAsJSON() throws ParseException, UnsupportedEncodingException {
        MGraph g = new IndexedMGraph();
        LiteralFactory lf = LiteralFactory.getInstance();
        MGraph metadata = contentItem.getMetadata();
        for (EntityExtractionSummary p : getPlaceOccurrences()) {
            EntitySuggestion bestGuess = p.getBestGuess();
            if (bestGuess == null) {
                continue;
            }
            UriRef uri = new UriRef(bestGuess.getUri());
            Iterator<Triple> latitudes = metadata.filter(uri, GEO_LAT, null);
            if (latitudes.hasNext()) {
                g.add(latitudes.next());
            }
            Iterator<Triple> longitutes = metadata.filter(uri, GEO_LONG, null);
            if (longitutes.hasNext()) {
                g.add(longitutes.next());
                g.add(new TripleImpl(uri, Properties.RDFS_LABEL, lf.createTypedLiteral(bestGuess.getLabel())));
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, g, SupportedFormat.RDF_JSON);
       
View Full Code Here

                "Failed to create OntoNet session. The Refactor Engine requires its own new session to execute.");

        log.debug("Refactor enhancement job will run in session '{}'.", session.getID());

        // Retrieve and filter the metadata graph for entities recognized by the engines.
        final MGraph metadataGraph = ci.getMetadata(), signaturesGraph = new IndexedMGraph();
        // FIXME the Stanbol Enhancer vocabulary should be retrieved from somewhere in the enhancer API.
        final UriRef ENHANCER_ENTITY_REFERENCE = new UriRef(
                "http://fise.iks-project.eu/ontology/entity-reference");
        Iterator<Triple> tripleIt = metadataGraph.filter(null, ENHANCER_ENTITY_REFERENCE, null);
        while (tripleIt.hasNext()) {
            // Get the entity URI
            Resource obj = tripleIt.next().getObject();
            if (!(obj instanceof UriRef)) {
                log.warn("Invalid UriRef for entity reference {}. Skipping.", obj);
                continue;
            }
            final String entityReference = ((UriRef) obj).getUnicodeString();
            log.debug("Trying to resolve entity {}", entityReference);

            // Populate the entity signatures graph, by querying either the Entity Hub or the dereferencer.
            if (engineConfiguration.isEntityHubUsed()) {
                MGraph result = populateWithEntity(entityReference, signaturesGraph);
                if (result != signaturesGraph && result != null) {
                    log.warn("Entity Hub query added triples to a new graph instead of populating the supplied one!"
                             + " New signatures will be discarded.");
                }
            } else try {
                OntologyInputSource<TripleCollection> source = new GraphContentSourceWithPhysicalIRI(
                        dereferencer.resolve(entityReference), IRI.create(entityReference));
                signaturesGraph.addAll(source.getRootOntology());
            } catch (FileNotFoundException e) {
                log.error("Failed to dereference entity " + entityReference + ". Skipping.", e);
                continue;
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.commons.indexedgraph.IndexedMGraph

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.