You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2011/10/04 14:13:59 UTC
svn commit: r1178765 [4/12] - in /incubator/stanbol/trunk/contenthub: ./
api/ api/src/ api/src/main/ api/src/main/java/ api/src/main/java/org/
api/src/main/java/org/apache/ api/src/main/java/org/apache/stanbol/
api/src/main/java/org/apache/stanbol/cont...
Added: incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/indexing/EnhancementLARQ.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/indexing/EnhancementLARQ.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/indexing/EnhancementLARQ.java (added)
+++ incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/indexing/EnhancementLARQ.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.core.utils.indexing;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.jena.commons.Tria2JenaUtil;
+import org.apache.clerezza.rdf.jena.facade.JenaGraph;
+import org.apache.stanbol.contenthub.core.utils.sparql.QueryGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.larq.IndexBuilderString;
+import com.hp.hpl.jena.query.larq.IndexLARQ;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+
+/**
+ *
+ * @author anil.sinaci
+ *
+ */
+public class EnhancementLARQ {
+
+ private static final Logger logger = LoggerFactory.getLogger(EnhancementLARQ.class);
+
+ private static EnhancementLARQ instance;
+
+ private Model enhancementModel;
+ private IndexBuilderString enhancementGraphIndexBuilder;
+
+ private EnhancementLARQ() {
+ enhancementModel = null;
+ enhancementGraphIndexBuilder = null;
+ }
+
+ public static EnhancementLARQ getInstance() {
+ if (instance == null) {
+ instance = new EnhancementLARQ();
+ }
+ return instance;
+ }
+
+ public void createIndex(MGraph mgraph) {
+ // FIXME: To index the enhancement graph, we need a Jena graph, however tcmanager
+ // is directly used in here. We need to use a common interface to eliminate this burden
+ // of converting one graph to other.
+ JenaGraph jenaGraph = new JenaGraph(mgraph);
+ enhancementModel = ModelFactory.createModelForGraph(jenaGraph);
+
+ // Build the LARQ index on the enhancement graph
+ // TODO We may build the index on a specific property
+ enhancementGraphIndexBuilder = new IndexBuilderString();
+ enhancementGraphIndexBuilder.indexStatements(enhancementModel.listStatements());
+ enhancementModel.register(enhancementGraphIndexBuilder);
+ logger.debug("EnhancementLARQ has indexed existing enhancement graph and started to listen");
+ }
+
+ public void updateIndex(Triple triple) {
+ Tria2JenaUtil jena2TriaUtil = new Tria2JenaUtil(null);
+ Resource subject = enhancementModel.createResource(jena2TriaUtil
+ .convert2JenaNode(triple.getSubject()).getURI());
+ Property predicate = enhancementModel.createProperty(jena2TriaUtil.convert2JenaNode(
+ triple.getPredicate()).getURI());
+ RDFNode object = enhancementModel.getRDFNode(jena2TriaUtil.convert2JenaNode(triple.getObject()));
+ Statement s = enhancementModel.createStatement(subject, predicate, object);
+ enhancementModel.add(s);
+ }
+
+ public Model getEnhancementModel() {
+ if (enhancementModel == null) {
+ logger.error("Enhancement Model in EnhancementLARQ is null. Index has not been created yet.");
+ return null;
+ }
+ return enhancementModel;
+ }
+
+ public IndexLARQ getIndex() {
+ if (enhancementGraphIndexBuilder == null) {
+ logger.error("enhancementGraphIndexBuilder in EnhancementLARQ is null. Index has not been created yet.");
+ return null;
+ }
+ return enhancementGraphIndexBuilder.getIndex();
+ }
+
+ public void deleteEnhancements(String contentID) {
+ enhancementModel.unregister(enhancementGraphIndexBuilder);
+ Query query = QueryFactory.create(QueryGenerator.getEnhancementsOfContent(contentID));
+ QueryExecution qexec = QueryExecutionFactory.create(query, enhancementModel);
+ List<String> enhancementsToBeRemoved = new ArrayList<String>();
+ try {
+ ResultSet results = qexec.execSelect();
+ while (results.hasNext()) {
+ QuerySolution soln = results.nextSolution();
+ enhancementsToBeRemoved.add(soln.getResource("enhancement").getURI());
+ }
+ } finally {
+ qexec.close();
+ }
+ for(String enhancementURI : enhancementsToBeRemoved) {
+ StmtIterator it = enhancementModel.listStatements(ResourceFactory.createResource(enhancementURI), (Property) null, (RDFNode) null);
+ if(it == null) continue;
+ enhancementModel.remove(it);
+ }
+ enhancementGraphIndexBuilder = new IndexBuilderString();
+ enhancementGraphIndexBuilder.indexStatements(enhancementModel.listStatements());
+ enhancementModel.register(enhancementGraphIndexBuilder);
+ }
+
+ public void printGraph() {
+ enhancementModel.write(System.out, "RDF/XML");
+ }
+
+
+}
Added: incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/sparql/QueryGenerator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/sparql/QueryGenerator.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/sparql/QueryGenerator.java (added)
+++ incubator/stanbol/trunk/contenthub/core/src/main/java/org/apache/stanbol/contenthub/core/utils/sparql/QueryGenerator.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.core.utils.sparql;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public class QueryGenerator {
+
+ public static final String getExternalPlacesQuery() {
+ /*
+ * String query = "PREFIX fise: <http://fise.iks-project.eu/ontology/>\n" +
+ * "PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>\n" +
+ * "PREFIX dc: <http://purl.org/dc/terms/>\n" + "SELECT distinct ?ref \n" + "WHERE {\n" +
+ * " ?enhancement a fise:EntityAnnotation .\n" + " ?enhancement dc:relation ?textEnh.\n" +
+ * " ?enhancement fise:entity-label ?label.\n" + " ?textEnh a fise:TextAnnotation .\n" +
+ * " ?enhancement fise:entity-type ?type.\n" + " ?enhancement2 dc:relation ?textEnh.\n" +
+ * " ?enhancement2 fise:entity-type ?type.\n" + " ?enhancement fise:entity-reference ?ref.\n" +
+ * "FILTER sameTerm(?type, <http://dbpedia.org/ontology/Place>) }\n" +
+ * "ORDER BY DESC(?extraction_time)";
+ */
+
+ String query = "PREFIX fise: <http://fise.iks-project.eu/ontology/>\n"
+ + "PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>\n"
+ + "PREFIX dc: <http://purl.org/dc/terms/>\n" + "SELECT distinct ?ref \n"
+ + "WHERE {\n" + " ?enhancement a fise:EntityAnnotation .\n"
+ + " ?enhancement dc:relation ?textEnh.\n"
+ + " ?enhancement fise:entity-label ?label.\n"
+ + " ?textEnh a fise:TextAnnotation .\n" + " ?enhancement fise:entity-type ?type.\n"
+ + " ?enhancement fise:entity-reference ?ref.\n"
+ + "FILTER sameTerm(?type, <http://dbpedia.org/ontology/Place>) }\n"
+ + "ORDER BY DESC(?extraction_time)";
+
+ return query;
+ }
+
+ public static final String getEnhancementsOfContent(String contentID) {
+ String enhancementQuery = "PREFIX enhancer: <http://fise.iks-project.eu/ontology/> "
+ + "SELECT DISTINCT ?enhancement WHERE { "
+ + " ?enhancement enhancer:extracted-from ?enhID . "
+ + " FILTER sameTerm(?enhID, <" + contentID + ">) } ";
+ return enhancementQuery;
+ }
+
+ public static final String getRecentlyEnhancedDocuments(int pageSize, int offset) {
+ String query = "PREFIX enhancer: <http://fise.iks-project.eu/ontology/> "
+ + "PREFIX dc: <http://purl.org/dc/terms/> " + "SELECT DISTINCT ?content WHERE { "
+ + " ?enhancement enhancer:extracted-from ?content ."
+ + " ?enhancement dc:created ?extraction_time . } "
+ + "ORDER BY DESC(?extraction_time) LIMIT %d OFFSET %d";
+ return String.format(query, pageSize, offset);
+ }
+}
Added: incubator/stanbol/trunk/contenthub/core/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/core/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/trunk/contenthub/core/src/main/resources/OSGI-INF/metatype/metatype.properties Tue Oct 4 12:13:49 2011
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#Properties defined by the yard interface and used by the solr Yard implementation
+org.apache.stanbol.entityhub.yard.solr.impl.SolrYard.name=Apache Stanbol Entityhub Yard: Solr Yard Configuration
+org.apache.stanbol.entityhub.yard.solr.impl.SolrYard.description=Used to configure a Yard (storage component of the Entityhub) based on a Solr instance
+
+#org.apache.stanbol.entityhub.yard.solr.solrUri
+org.apache.stanbol.entityhub.yard.solr.solrUri.name=Solr Index/Core
+org.apache.stanbol.entityhub.yard.solr.solrUri.description=This can be either the URL of a SolrServer, the absolute Path to an index/core an the local file system or just the core name to use the EmbeddedSolrServer internally managed by the SolrYard
+
+#org.apache.stanbol.entityhub.yard.solr.multiYardIndexLayout
+org.apache.stanbol.entityhub.yard.solr.multiYardIndexLayout.name=Multiple Yard Layout
+org.apache.stanbol.entityhub.yard.solr.multiYardIndexLayout.description=If several Yards are using the same Solr index than set this property to TRUE. NOTE: That this is only an option if all Yards using the same Solr Index do not store Representations with the same URI!
+
+#org.apache.stanbol.entityhub.yard.id
+org.apache.stanbol.entityhub.yard.id.name=ID
+org.apache.stanbol.entityhub.yard.id.description=The unique ID for the Yard
+
+#org.apache.stanbol.entityhub.yard.name
+org.apache.stanbol.entityhub.yard.name.name=name
+org.apache.stanbol.entityhub.yard.name.description=The human readable name for the Yard
+
+#org.apache.stanbol.entityhub.yard.Description
+org.apache.stanbol.entityhub.yard.description.name=description
+org.apache.stanbol.entityhub.yard.description.description=Typically short description describing what kind of Data are stored in this Yard (e.g. local Cache for DBPedia)
+
+#org.apache.stanbol.entityhub.yard.solr.maxQueryResultNumber
+org.apache.stanbol.entityhub.yard.maxQueryResultNumber.name=Maximum Query Results
+org.apache.stanbol.entityhub.yard.maxQueryResultNumber.description=The maximum number of results per query (set to <= 0 for no restriction). If a parsed query asks for more results, than that value will be replaced by the value configured.
+
+#org.apache.stanbol.entityhub.yard.solr.defaultQueryResultNumber
+org.apache.stanbol.entityhub.yard.defaultQueryResultNumber.name=Default Query Results
+org.apache.stanbol.entityhub.yard.defaultQueryResultNumber.description=The default number of results set for queries that do not define such a value (set to <= 0 for no restriction, values > maximumQueryResult will be replaced by maximumQueryResult)
+
+#org.apache.stanbol.entityhub.yard.solr.maxBooleanClauses
+org.apache.stanbol.entityhub.yard.solr.maxBooleanClauses.name=Max Boolean Clauses
+org.apache.stanbol.entityhub.yard.solr.maxBooleanClauses.description=This is the maximum number of boolean clauses allowed for Solr queries. This value is configured in the solrconf.xml by the maxBooleanClauses element.
Added: incubator/stanbol/trunk/contenthub/core/src/main/resources/solr/core/contenthub.solrindex.zip
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/core/src/main/resources/solr/core/contenthub.solrindex.zip?rev=1178765&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/stanbol/trunk/contenthub/core/src/main/resources/solr/core/contenthub.solrindex.zip
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Propchange: incubator/stanbol/trunk/contenthub/enhancementlistener/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 4 12:13:49 2011
@@ -0,0 +1,4 @@
+target
+.settings
+.classpath
+.project
Added: incubator/stanbol/trunk/contenthub/enhancementlistener/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/enhancementlistener/pom.xml?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/enhancementlistener/pom.xml (added)
+++ incubator/stanbol/trunk/contenthub/enhancementlistener/pom.xml Tue Oct 4 12:13:49 2011
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+
+ <artifactId>org.apache.stanbol.contenthub.enhancementlistener</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Contenthub Enhancement Listener</name>
+
+ <description>Listens enhancement changes on a clerezza graph, and submits them to entity hub.</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Embed-Dependency>jtidy|htmlcleaner</Embed-Dependency>
+ <Import-Package>
+ !org.jdom,
+ !org.apache.tools.ant,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.facade</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>jena</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>arq</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/EnhancementListenerFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/EnhancementListenerFactory.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/EnhancementListenerFactory.java (added)
+++ incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/EnhancementListenerFactory.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.helper.enhancementlistener;
+
+/**
+ * @author anil.sinaci
+ *
+ */
+public interface EnhancementListenerFactory {
+
+ public static final String ENTITY_HUB_PROP = "org.apache.stanbol.search.helper.enhancement_listener.entityHubEndpoint";
+ public static final String ENTITY_HUB_VALUE = "http://localhost:8080/entityhub";
+
+}
Added: incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListener.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListener.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListener.java (added)
+++ incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListener.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.helper.enhancementlistener.tcmanager;
+
+import java.util.List;
+import java.util.concurrent.Semaphore;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.event.AddEvent;
+import org.apache.clerezza.rdf.core.event.FilterTriple;
+import org.apache.clerezza.rdf.core.event.GraphEvent;
+import org.apache.clerezza.rdf.core.event.GraphListener;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.sparql.ParseException;
+import org.apache.clerezza.rdf.core.sparql.QueryParser;
+import org.apache.clerezza.rdf.core.sparql.ResultSet;
+import org.apache.clerezza.rdf.core.sparql.SolutionMapping;
+import org.apache.clerezza.rdf.core.sparql.query.SelectQuery;
+import org.apache.stanbol.contenthub.core.utils.EntityHubClient;
+import org.apache.stanbol.contenthub.core.utils.indexing.EnhancementLARQ;
+import org.apache.stanbol.contenthub.core.utils.sparql.QueryGenerator;
+import org.apache.stanbol.contenthub.servicesapi.enhancements.vocabulary.EnhancementGraphVocabulary;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author anil.sinaci
+ *
+ */
+public class EnhancementListener {
+ private static final Logger logger = LoggerFactory.getLogger(EnhancementListener.class);
+
+ private final GraphListener listener;
+ private MGraph mGraph;
+ private boolean active = false;
+
+ public EnhancementListener(TcManager tcManager, String entityHubURI) {
+ UriRef graphRef = new UriRef(EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI);
+ boolean graphExists = tcManager.listMGraphs().contains(graphRef);
+ // FIXME To allow this component to work for non-existing graphs, the graph is created here.
+ // It is better to create this graph in somewhere else
+ if (!graphExists) {
+ tcManager.createMGraph(graphRef);
+ }
+
+ EntityHubClient entityHubClient = EntityHubClient.getInstance(entityHubURI);
+ this.mGraph = tcManager.getMGraph(graphRef);
+ EnhancementLARQ.getInstance().createIndex(this.mGraph);
+ this.listener = new Listener(tcManager, entityHubClient);
+ }
+
+ public void listen() {
+ if (!this.active) {
+ this.mGraph.addGraphListener(listener, new FilterTriple(null, null, null), 1000);
+ logger.debug("Started listening graph {} ", this.mGraph.toString());
+ this.active = true;
+ }
+ }
+
+ public void unlisten() {
+ if (this.active) {
+ this.mGraph.removeGraphListener(this.listener);
+ logger.debug("Stopped listening graph {}", this.mGraph.toString());
+ this.active = false;
+ }
+ }
+
+ private final class Listener implements GraphListener {
+
+ private TcManager tcManager;
+ private EntityHubClient entityHubClient;
+ private Semaphore sem = new Semaphore(1);
+
+ public Listener(TcManager tcManager, EntityHubClient entityHubClient) {
+ this.tcManager = tcManager;
+ this.entityHubClient = entityHubClient;
+ }
+
+ @Override
+ public void graphChanged(List<GraphEvent> arg0) {
+
+ SimpleMGraph newEnhancements = new SimpleMGraph();
+ for (GraphEvent e : arg0) {
+ if(e instanceof AddEvent) {
+ EnhancementLARQ.getInstance().updateIndex(e.getTriple());
+ newEnhancements.add(e.getTriple());
+ }
+ }
+
+ try {
+ this.sem.acquire();
+ SelectQuery query = (SelectQuery) QueryParser.getInstance().parse(
+ QueryGenerator.getExternalPlacesQuery());
+ ResultSet result = tcManager.executeSparqlQuery(query, newEnhancements);
+ while (result.hasNext()) {
+ SolutionMapping sol = result.next();
+ String uri = sol.get("ref").toString();
+ if (uri != null) {
+ uri = uri.replaceAll("\\<|\\>", "");
+ logger.debug("Found resource {} on graph {}. Trying to submit to entity hub",
+ newEnhancements.toString(), uri);
+ try {
+ logger.debug(
+ "Enhancement listener is calling entityhubclient.symbollookup with uri: {}",
+ uri);
+ entityHubClient.symbolLookup(uri, true);
+ logger.debug("Added symbol {} to entity hub");
+ } catch (Exception e) {
+ logger.debug("Error at submitting {} to entity hub at {}", uri,
+ entityHubClient.getEntityhubEndpoint());
+ logger.error("Error from entity hub", e);
+ }
+ } else {
+ logger.info("Found ehancement result without any URIs on graph {}",
+ newEnhancements.toString());
+ }
+ }
+ } catch (InterruptedException e) {
+ logger.error("Error at acquiring lock", e);
+ } catch (ParseException e) {
+ // Should never reach here
+ logger.error("Settlement Query can not be parsed", e);
+ } finally {
+ // release acquired semaphore
+ this.sem.release();
+ }
+ }
+ }
+}
Added: incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListenerFactoryTCM.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListenerFactoryTCM.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListenerFactoryTCM.java (added)
+++ incubator/stanbol/trunk/contenthub/enhancementlistener/src/main/java/org/apache/stanbol/contenthub/helper/enhancementlistener/tcmanager/EnhancementListenerFactoryTCM.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.helper.enhancementlistener.tcmanager;
+
+import java.util.Dictionary;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.contenthub.helper.enhancementlistener.EnhancementListenerFactory;
+import org.apache.stanbol.contenthub.servicesapi.enhancements.vocabulary.EnhancementGraphVocabulary;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author anil.sinaci
+ *
+ */
+@Component(metatype = true, immediate = true)
+@Service
+public class EnhancementListenerFactoryTCM implements EnhancementListenerFactory {
+
+ private static final Logger logger = LoggerFactory.getLogger(EnhancementListenerFactoryTCM.class);
+
+ @Property(name = EnhancementListenerFactory.ENTITY_HUB_PROP, value = EnhancementListenerFactory.ENTITY_HUB_VALUE)
+ private String entityHubURI;
+
+ @Reference
+ private TcManager tcManager;
+
+ private EnhancementListener enhancementListener;
+
+ @Activate
+ protected void activate(ComponentContext cc) {
+ logger.debug("Activating Ehnhancement Listener Factory");
+ @SuppressWarnings("rawtypes")
+ Dictionary properties = cc.getProperties();
+ try {
+ entityHubURI = (String) properties.get(EnhancementListenerFactory.ENTITY_HUB_PROP);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Configuration problem at starting enhancement listener factory", e);
+ }
+
+ if (enhancementListener == null) {
+ try {
+ enhancementListener = new EnhancementListener(tcManager, entityHubURI);
+ enhancementListener.listen();
+ logger.debug("Listener for graph {} is created",
+ EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI);
+ } catch (Exception e) {
+ logger.warn("Problem creating listener for graph {}",
+ EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI);
+ logger.error("Error on listener creation", e);
+ }
+ } else {
+ enhancementListener.listen();
+ logger.debug("Graph {} is already being listened, no new listener is created",
+ EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI);
+ }
+ }
+
+ @Deactivate
+ protected void deactivate(ComponentContext cc) {
+ logger.debug("Deactivating Enhancement Listener Factory");
+ enhancementListener.unlisten();
+ }
+
+ /**
+ @Override
+ public Model getEnhancementModel() {
+ if (this.enhancementListener == null) {
+ logger.warn("Listener for graph {} is not ready yet.",
+ EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI);
+ return null;
+ }
+ return this.enhancementListener.getEnhancementModel();
+ }
+
+ @Override
+ public IndexLARQ getIndex() {
+ if (this.enhancementListener == null) {
+ logger.warn("Listener for graph {} is not ready yet.",
+ EnhancementGraphVocabulary.ENHANCEMENTS_GRAPH_URI);
+ return null;
+ }
+ return this.enhancementListener.getIndex();
+ }
+ */
+
+}
Propchange: incubator/stanbol/trunk/contenthub/helper/cnn-importer/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 4 12:13:49 2011
@@ -0,0 +1,4 @@
+target
+.settings
+.classpath
+.project
Added: incubator/stanbol/trunk/contenthub/helper/cnn-importer/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/helper/cnn-importer/pom.xml?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/helper/cnn-importer/pom.xml (added)
+++ incubator/stanbol/trunk/contenthub/helper/cnn-importer/pom.xml Tue Oct 4 12:13:49 2011
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <artifactId>org.apache.stanbol.contenthub.helper.cnn</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Contenthub CNN News Importer</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Embed-Dependency>jtidy|htmlcleaner</Embed-Dependency>
+ <Import-Package>
+ !org.jdom,
+ !org.apache.tools.ant,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.servicesapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlcleaner</groupId>
+ <artifactId>htmlcleaner</artifactId>
+ <version>2.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>jtidy</groupId>
+ <artifactId>jtidy</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/CNNImporter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/CNNImporter.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/CNNImporter.java (added)
+++ incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/CNNImporter.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.helper.cnn;
+
+import java.net.URI;
+import java.util.List;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public interface CNNImporter {
+
+ List<URI> importCNNNews(String topic, int maxNumber, boolean fullNews);
+
+}
Added: incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/CNNImporterImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/CNNImporterImpl.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/CNNImporterImpl.java (added)
+++ incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/CNNImporterImpl.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.helper.cnn.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.contenthub.helper.cnn.CNNImporter;
+import org.apache.stanbol.contenthub.servicesapi.store.SolrContentItem;
+import org.apache.stanbol.contenthub.servicesapi.store.SolrStore;
+import org.htmlcleaner.HtmlCleaner;
+import org.htmlcleaner.TagNode;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.tidy.Tidy;
+
+/**
+ *
+ * @author cihan
+ * @author anil.sinaci
+ *
+ */
+@Component(metatype = true)
+@Service
+public class CNNImporterImpl implements CNNImporter {
+ private static final Logger logger = LoggerFactory.getLogger(CNNImporterImpl.class);
+
+ private static final String CNN_URL = "http://topics.cnn.com/topics/";
+ private static final String TEXT_CLASS = "cnn_strycntntlft";
+
+ @Reference
+ private SolrStore solrStore;
+
+ @Activate
+ public void activate(ComponentContext cc) {
+ if(solrStore == null) {
+ logger.error("Cannot activate CNNImporter. There is no SolrStore to be binded.");
+ }
+ }
+
+ @Override
+ public List<URI> importCNNNews(String topic, int maxNumber, boolean fullNews) {
+ List<NewsSummary> summaries = getRelatedNews(topic, maxNumber);
+ List<URI> uris = new ArrayList<URI>();
+ if (fullNews) {
+ for (NewsSummary summary : summaries) {
+ String realContent = getNewsContent(summary.getNewsURI());
+ if (realContent != null && !realContent.isEmpty()) {
+ summary.setContent(realContent);
+ }
+ }
+ }
+
+ for (NewsSummary summary : summaries) {
+ try {
+ SolrContentItem sci = solrStore.create(null, summary.getContent().getBytes(), "text/plain", null);
+ URI uri = new URI(solrStore.enhanceAndPut(sci));
+ if (uri != null) {
+ uris.add(uri);
+ }
+ } catch (Exception e) {
+ logger.error("", e);
+ logger.warn("Error storing content {}. Skipping ...", summary.getContent());
+ }
+ }
+ return uris;
+ }
+
+ private String getNewsContent(URI newsURI) {
+ try {
+ URL newsURL = newsURI.toURL();
+ HtmlCleaner cleaner = new HtmlCleaner();
+ TagNode root = cleaner.clean(newsURL);
+ Object[] text = root.evaluateXPath("//div[@class='" + TEXT_CLASS + "']");
+ StringBuilder realContent = new StringBuilder();
+ for (Object storyPart : text) {
+
+ try {
+ TagNode storyFragment = (TagNode) storyPart;
+ for (TagNode child : storyFragment.getChildTags()) {
+ if (child.getName().equals("p")) {
+ realContent.append(child.getText().toString());
+ }
+ }
+ } catch (ClassCastException e) {
+ logger.debug("Can not cast {} to TagNode", storyPart.getClass());
+ }
+ }
+ return realContent.toString();
+ } catch (Exception e) {
+ logger.warn("Unable to get real content of the news {}", newsURI.toString());
+ }
+ return null;
+
+ }
+
+ private List<NewsSummary> getRelatedNews(String topic, int maxNumber) {
+ List<NewsSummary> summaries = new ArrayList<NewsSummary>();
+ try {
+ URL topicURL = new URL(CNN_URL + topic.toLowerCase().replaceAll(" ", "_"));
+ Tidy tidy = new Tidy();
+ Document doc = tidy.parseDOM(topicURL.openStream(), new ByteArrayOutputStream());
+ NodeList nodes = doc.getDocumentElement().getElementsByTagName("div");
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node current = nodes.item(i);
+ NamedNodeMap atts = current.getAttributes();
+ Node classAtt = atts.getNamedItem("class");
+ if (classAtt != null
+ && classAtt.getNodeValue().equals(
+ "cnnRelatedArticle archive-item story cnn_skn_spccovstrylst")) {
+ NewsSummary summary = createSummary((Element) current);
+ if (summary != null) {
+ summaries.add(summary);
+ }
+ }
+ if (summaries.size() >= maxNumber) {
+ break;
+ }
+ }
+ } catch (MalformedURLException e) {
+ logger.warn("Topic {} results in malformed url.", topic);
+ } catch (IOException e) {
+ logger.warn("Can get content of topic {}.", topic);
+ }
+ return summaries;
+ }
+
+ private NewsSummary createSummary(Element current) {
+ NewsSummary newsSummary = null;
+ try {
+ String summary = current.getElementsByTagName("p").item(0).getFirstChild().getNodeValue();
+ String uri = ((Element) current.getElementsByTagName("a").item(0)).getAttribute("href");
+ newsSummary = new NewsSummary();
+ newsSummary.setNewsURI(new URI(uri));
+ newsSummary.setContent(summary);
+ } catch (Exception e) {
+ newsSummary = null;
+ logger.warn("Error creating summary from node {}", current);
+ }
+ return newsSummary;
+ }
+
+}
Added: incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/NewsSummary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/NewsSummary.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/NewsSummary.java (added)
+++ incubator/stanbol/trunk/contenthub/helper/cnn-importer/src/main/java/org/apache/stanbol/contenthub/helper/cnn/impl/NewsSummary.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.helper.cnn.impl;
+
+import java.net.URI;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public class NewsSummary {
+
+ private URI newsURI;
+ private String content;
+
+ public void setNewsURI(URI newsURI) {
+ this.newsURI = newsURI;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public URI getNewsURI() {
+ return newsURI;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+}
Propchange: incubator/stanbol/trunk/contenthub/parent/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 4 12:13:49 2011
@@ -0,0 +1,3 @@
+target
+.settings
+.project
Added: incubator/stanbol/trunk/contenthub/parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/parent/pom.xml?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/parent/pom.xml (added)
+++ incubator/stanbol/trunk/contenthub/parent/pom.xml Tue Oct 4 12:13:49 2011
@@ -0,0 +1,213 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>stanbol-parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>../../parent</relativePath>
+ </parent>
+
+ <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Apache Stanbol Contenthub parent POM</name>
+ <description>
+ Parent POM for the Apache Stanbol Contenthub component
+ </description>
+
+ <inceptionYear>2011</inceptionYear>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/contenthub/parent
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/contenthub/parent
+ </developerConnection>
+ <url>http://incubator.apache.org/stanbol</url>
+ </scm>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <stanbol-version>0.9.0-incubating-SNAPSHOT</stanbol-version>
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-Category>Stanbol Contenthub</Bundle-Category>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Search -->
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.core</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.web</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.search.engines.wordnet</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Search External -->
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>edu.smu.tspell.jaws</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Search Helper -->
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.helper.cnn</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- CMS Adapter -->
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.cmsadapter.servicesapi</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Ontology Manager Store
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.api</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.rest</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.rest.client</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.jena</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.adapter</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.jena.tdb</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.ontologymanager.store.clerezza</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ -->
+
+ <!-- Clerezza -->
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.facade</artifactId>
+ <version>0.12-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Wordnet -->
+ <dependency>
+ <groupId>edu.smu.tspell</groupId>
+ <artifactId>jaws</artifactId>
+ <version>1.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- JTidy -->
+ <dependency>
+ <groupId>jtidy</groupId>
+ <artifactId>jtidy</artifactId>
+ <version>4aug2000r7-dev</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- JAXB (Although jaxb is part of Java 6 at runtime on Felix ClassNotFoundExceptions
+ of jaxb classes are thrown) -->
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.2.2</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Jersey -->
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>${jersey-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+</project>
Added: incubator/stanbol/trunk/contenthub/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/pom.xml?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/pom.xml (added)
+++ incubator/stanbol/trunk/contenthub/pom.xml Tue Oct 4 12:13:49 2011
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>./parent</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.reactor</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Apache Stanbol Contenthub Reactor</name>
+ <description>
+ Pseudo project to build the complete Contenthub bundle
+ </description>
+
+ <inceptionYear>2011</inceptionYear>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/contenthub/
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/contenthub/
+ </developerConnection>
+ </scm>
+
+ <modules>
+ <module>parent</module>
+ <module>api</module>
+ <module>core</module>
+ <module>search</module>
+ <module>helper/cnn-importer</module>
+ <module>enhancementlistener</module>
+ <module>web</module>
+ <!--
+ <module>launchers/full</module>
+ -->
+ </modules>
+</project>
Propchange: incubator/stanbol/trunk/contenthub/search/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 4 12:13:49 2011
@@ -0,0 +1,3 @@
+target
+.settings
+.project
Added: incubator/stanbol/trunk/contenthub/search/README.md
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/README.md?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/README.md (added)
+++ incubator/stanbol/trunk/contenthub/search/README.md Tue Oct 4 12:13:49 2011
@@ -0,0 +1,33 @@
+## Building Search Component
+
+* Checkout Apache Stanbol
+ $ svn co http://svn.apache.org/repos/asf/incubator/stanbol/trunk/
+* Build Stanbol [see] (http://svn.apache.org/repos/asf/incubator/stanbol/trunk/README.md)
+* Build Stanbol Ontology Manager - Store
+ $ cd trunk/ontologymanager/store
+ $ mvn install
+* Build Stanbol Commons Web Ontology
+ $ cd trunk/commons/web/ontology
+ $ mvn install
+* Go to Search component working copy root (/sandbox/search)
+ $ mvn install
+
+## Running
+
+* Run full launcher
+ $ cd launchers/full
+ $ java -jar -Xmx1024m -XX:MaxPermSize=128m target/org.apache.stanbol.search.launchers.full-0.9-SNAPSHOT.jar
+
+## Configuration
+
+* Configure EntityHub endpoint from [Apache Felix Web Console](http://localhost:8080/system/console/configMgr/org.apache.stanbol.search.engines.location.LocationSearchEngine)
+* (OPTIONAL) Configure ContentHub endpoint from [Apache Felix Web Console](http://localhost:8080/system/console/configMgr/org.apache.stanbol.search.helper.cnn.imp.CNNImporterImp)
+
+## Try
+
+* Go to http://localhost:8080/search/import
+* Insert:
+ Topic: Tokyo
+ Click Import News, wait for the links of the imported documents to appear
+* Go to http://localhost:8080/search, Search for Japan, check Tokyo keyword in results.
+
Propchange: incubator/stanbol/trunk/contenthub/search/engines/enhancement/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 4 12:13:49 2011
@@ -0,0 +1,4 @@
+.settings
+target
+.project
+.classpath
Added: incubator/stanbol/trunk/contenthub/search/engines/enhancement/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/enhancement/pom.xml?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/enhancement/pom.xml (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/enhancement/pom.xml Tue Oct 4 12:13:49 2011
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>../../../parent</relativePath>
+ </parent>
+
+ <artifactId>org.apache.stanbol.contenthub.search.engines.enhancer</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Search Enhancement Searcher</name>
+
+ <description>Finds ontlogy classes and individuals based Enhancer enhancements.</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>jena</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>arq</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.servicesapi</artifactId>
+ </dependency>
+ <!-- should be moved in to contenthub or apache-stanbol parent pom.xml -->
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.enhancementlistener</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <type>bundle</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/EnhancementSearchEngine.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/EnhancementSearchEngine.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/EnhancementSearchEngine.java (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/EnhancementSearchEngine.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.search.engines.enhancement;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.contenthub.core.utils.indexing.EnhancementLARQ;
+import org.apache.stanbol.contenthub.search.engines.enhancement.model.EnhancementPool;
+import org.apache.stanbol.contenthub.search.engines.enhancement.model.EnhancementRepresentation;
+import org.apache.stanbol.contenthub.search.engines.enhancement.model.EntityRepresentation;
+import org.apache.stanbol.contenthub.servicesapi.search.engine.EngineProperties;
+import org.apache.stanbol.contenthub.servicesapi.search.engine.SearchEngine;
+import org.apache.stanbol.contenthub.servicesapi.search.engine.SearchEngineException;
+import org.apache.stanbol.contenthub.servicesapi.search.execution.DocumentResource;
+import org.apache.stanbol.contenthub.servicesapi.search.execution.ExternalResource;
+import org.apache.stanbol.contenthub.servicesapi.search.execution.Keyword;
+import org.apache.stanbol.contenthub.servicesapi.search.execution.QueryKeyword;
+import org.apache.stanbol.contenthub.servicesapi.search.execution.SearchContext;
+import org.apache.stanbol.contenthub.servicesapi.search.execution.SearchContextFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.larq.IndexLARQ;
+import com.hp.hpl.jena.query.larq.LARQ;
+import com.hp.hpl.jena.rdf.model.Model;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+@Component
+@Service
+public class EnhancementSearchEngine implements SearchEngine, EngineProperties {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EnhancementSearchEngine.class);
+
+ private static final Map<String,Object> properties;
+ static {
+ properties = new HashMap<String,Object>();
+ properties.put(PROCESSING_ORDER, PROCESSING_DEFAULT);
+ }
+
+ Model enhancementGraph = null;
+
+ @Override
+ public void search(SearchContext searchContext) throws SearchEngineException {
+ // FIXME: can be done in activator, but DOES ENHANCEMENTGRAPH CHANGES AFTER ACTIVATION?
+ enhancementGraph = EnhancementLARQ.getInstance().getEnhancementModel();
+ if (enhancementGraph != null) {
+ for (QueryKeyword qk : searchContext.getQueryKeyWords()) {
+ searchForKeyword(qk, searchContext);
+ for (Keyword kw : qk.getRelatedKeywords()) {
+ searchForKeyword(kw, searchContext);
+ }
+ }
+ } else {
+ LOGGER.info("EnhancementGraph could not be obtained, skipped enhancement Search Engine");
+ }
+
+ }
+
+ private void searchForKeyword(Keyword keyword, SearchContext context) {
+ LOGGER.debug("Started searching for keyword {} ", keyword.getKeyword());
+ String query = QueryGenerator.keywordBasedAnnotationQuery(keyword.getKeyword());
+ IndexLARQ index = EnhancementLARQ.getInstance().getIndex();
+ if (index != null) {
+ QueryExecution qExec = QueryExecutionFactory.create(query, enhancementGraph);
+ LARQ.setDefaultIndex(qExec.getContext(), index);
+ ResultSet result = qExec.execSelect();
+ processResults(result, keyword, context);
+ } else {
+ LOGGER.info("LARQ Index could not be obtained from Enhancement Listener Factory");
+ }
+ }
+
+ private void processResults(ResultSet result, Keyword keyword, SearchContext context) {
+ SearchContextFactory scf = context.getFactory();
+ while (result.hasNext()) {
+ QuerySolution resultBinding = result.nextSolution();
+ String label = resultBinding.getLiteral("label").getString();
+ double score = resultBinding.getLiteral("score").getDouble();
+ String document = resultBinding.getResource("document").getURI();
+ String type = resultBinding.getResource("type").getURI();
+ String selectionText = resultBinding.getLiteral("text").getString();
+ String ref = resultBinding.getResource("ref").getURI();
+ double refScore = resultBinding.getLiteral("refscore").getDouble();
+
+ EnhancementRepresentation er = EnhancementPool.getEnhancementRepresentation(label, document);
+ EntityRepresentation etr = EnhancementPool.getEntityRepresentation(ref, label, document);
+ er.setScore((score > 10 ? 1 : score / 10.0));
+ er.setSelectionText(selectionText);
+ etr.setScore((refScore > 10 ? 1 : refScore / 10.0));
+ etr.getTypes().add(type);
+
+ }
+
+ for (EnhancementRepresentation er : EnhancementPool.getAll()) {
+ DocumentResource dr = scf.createDocumentResource(er.getDocument(), 1.0, er.getScore(), keyword,
+ er.getSelectionText());
+ for (EntityRepresentation etr : er.getExternalResources()) {
+ ExternalResource exr = scf.createExternalResource(etr.getRef(), 1.0, etr.getScore(), dr
+ .getRelatedKeywords().get(0));
+ for (String type : etr.getTypes()) {
+ exr.addType(type);
+ exr.addRelatedDocument(dr);
+ }
+ }
+ }
+
+ EnhancementPool.clear();
+ }
+
+ @Override
+ public Map<String,Object> getEngineProperties() {
+ return properties;
+ }
+
+}
Added: incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/QueryGenerator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/QueryGenerator.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/QueryGenerator.java (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/QueryGenerator.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.search.engines.enhancement;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public class QueryGenerator {
+
+ public static final String keywordBasedAnnotationQuery(String keyword) {
+ String query = "PREFIX fise: <http://fise.iks-project.eu/ontology/>\n"
+ + "PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>\n"
+ + "PREFIX dc: <http://purl.org/dc/terms/>\n" + "PREFIX crv: <http://cms.item#>\n"
+ + "SELECT distinct ?label ?score ?document ?type ?text ?ref ?refscore ?path\n"
+ + "WHERE {\n" + " ?enhancement a fise:EntityAnnotation .\n"
+ + " ?enhancement dc:relation ?textEnh.\n"
+ + " ?enhancement fise:entity-label ?label.\n"
+ + " ?textEnh a fise:TextAnnotation .\n"
+ + " ?textEnh fise:extracted-from ?document .\n"
+ + " ?enhancement fise:entity-type ?type.\n"
+ + " ?enhancement fise:entity-reference ?ref.\n"
+ + " ?enhancement fise:confidence ?refscore.\n"
+ + " ?textEnh fise:selection-context ?text.\n" + " (?label ?score) pf:textMatch '+"
+ + normalizeKeyword(keyword) + "'. \n" + "OPTIONAL {?enhancement crv:path ?path} \n"
+ + "}\n" + "ORDER BY DESC(?extraction_time)";
+ return query;
+ }
+
+ private static String normalizeKeyword(String keyword) {
+ return keyword.replace("'", "");
+ }
+
+}
Added: incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementPool.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementPool.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementPool.java (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementPool.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.search.engines.enhancement.model;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public class EnhancementPool {
+
+ private static Map<String,EnhancementRepresentation> enhancements = new HashMap<String,EnhancementRepresentation>();
+ private static Map<String,EntityRepresentation> entities = new HashMap<String,EntityRepresentation>();
+
+ public static EnhancementRepresentation getEnhancementRepresentation(String label, String document) {
+ String key = label + document;
+ if (!enhancements.containsKey(key)) {
+ EnhancementRepresentation er = new EnhancementRepresentation(label, document);
+ enhancements.put(key, er);
+ }
+ return enhancements.get(key);
+ }
+
+ public static EntityRepresentation getEntityRepresentation(String ref, String label, String document) {
+ String key = ref + document;
+ EnhancementRepresentation er = getEnhancementRepresentation(label, document);
+ if (!entities.containsKey(key)) {
+ EntityRepresentation etr = new EntityRepresentation(ref);
+ er.getExternalResources().add(etr);
+ entities.put(key, etr);
+ }
+ return entities.get(key);
+ }
+
+ public static Collection<EnhancementRepresentation> getAll() {
+ return enhancements.values();
+ }
+
+ public static void clear() {
+ enhancements.clear();
+ entities.clear();
+ }
+}
Added: incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementRepresentation.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementRepresentation.java (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EnhancementRepresentation.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.search.engines.enhancement.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public class EnhancementRepresentation {
+
+ private String selectionText;
+ private String label;
+ private double score;
+ private String document;
+ private List<EntityRepresentation> externalResources = new ArrayList<EntityRepresentation>();
+
+ EnhancementRepresentation(String label, String document) {
+ this.label = label;
+ this.document = document;
+ }
+
+ public void setSelectionText(String selectionText) {
+ this.selectionText = selectionText;
+ }
+
+ public void setScore(double score) {
+ this.score = score;
+ }
+
+ public String getDocument() {
+ return document;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public double getScore() {
+ return score;
+ }
+
+ public String getSelectionText() {
+ return selectionText;
+ }
+
+ public List<EntityRepresentation> getExternalResources() {
+ return externalResources;
+ }
+
+}
Added: incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EntityRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EntityRepresentation.java?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EntityRepresentation.java (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/enhancement/src/main/java/org/apache/stanbol/contenthub/search/engines/enhancement/model/EntityRepresentation.java Tue Oct 4 12:13:49 2011
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.contenthub.search.engines.enhancement.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author cihan
+ *
+ */
+public class EntityRepresentation {
+
+ private String ref;
+ private List<String> types = new ArrayList<String>();
+ private double score;
+
+ public EntityRepresentation(String ref) {
+ this.ref = ref;
+ }
+
+ public String getRef() {
+ return ref;
+ }
+
+ public void setScore(double score) {
+ this.score = score;
+ }
+
+ public double getScore() {
+ return score;
+ }
+
+ public List<String> getTypes() {
+ return types;
+ }
+}
Propchange: incubator/stanbol/trunk/contenthub/search/engines/ontologyresource/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 4 12:13:49 2011
@@ -0,0 +1,4 @@
+.classpath
+target
+.settings
+.project
Added: incubator/stanbol/trunk/contenthub/search/engines/ontologyresource/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/search/engines/ontologyresource/pom.xml?rev=1178765&view=auto
==============================================================================
--- incubator/stanbol/trunk/contenthub/search/engines/ontologyresource/pom.xml (added)
+++ incubator/stanbol/trunk/contenthub/search/engines/ontologyresource/pom.xml Tue Oct 4 12:13:49 2011
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.parent</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ <relativePath>../../../parent</relativePath>
+ </parent>
+
+ <artifactId>org.apache.stanbol.contenthub.search.engines.ontologyresource</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Search Ontology Resource Searcher</name>
+
+ <description>Finds ontlogy classes and individuals based on query keywords</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Embed-Dependency>jaws</Embed-Dependency>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>jena</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>arq</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>