Author: suat
Date: Tue Nov 27 10:36:32 2012
New Revision: 1414111

URL: http://svn.apache.org/viewvc?rev=1414111&view=rev
Log:
A missing file for the commit:

STANBOL-781:
Currently, when a ContentItem is submitted to an index which was created using 
a custom LDPath, the LDPath is only executed on the recognized entities through 
the Entityhub. This aims to gather additional information regarding to the 
entities of the ContentItem.

However, we would need to execute custom LDPath programs on additional RDF 
parts of ContentItems. Otherwise, it is not possible benefit from the 
additional parts. With this commit, SemanticIndexManagerImpl will execute the 
LDPath program on the RDF parts of ContentItem through the ContentItemBackend.

Modified:
    
stanbol/trunk/contenthub/ldpath/src/main/java/org/apache/stanbol/contenthub/ldpath/solr/SemanticIndexManagerImpl.java
    stanbol/trunk/contenthub/store/solr/pom.xml

Modified: 
stanbol/trunk/contenthub/ldpath/src/main/java/org/apache/stanbol/contenthub/ldpath/solr/SemanticIndexManagerImpl.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/contenthub/ldpath/src/main/java/org/apache/stanbol/contenthub/ldpath/solr/SemanticIndexManagerImpl.java?rev=1414111&r1=1414110&r2=1414111&view=diff
==============================================================================
--- 
stanbol/trunk/contenthub/ldpath/src/main/java/org/apache/stanbol/contenthub/ldpath/solr/SemanticIndexManagerImpl.java
 (original)
+++ 
stanbol/trunk/contenthub/ldpath/src/main/java/org/apache/stanbol/contenthub/ldpath/solr/SemanticIndexManagerImpl.java
 Tue Nov 27 10:36:32 2012
@@ -19,14 +19,17 @@ package org.apache.stanbol.contenthub.ld
 import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
+import java.io.StringReader;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
+import org.apache.clerezza.rdf.core.Resource;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.felix.scr.annotations.Activate;
@@ -39,6 +42,9 @@ import org.apache.stanbol.contenthub.ser
 import org.apache.stanbol.contenthub.servicesapi.ldpath.SemanticIndexManager;
 import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
 import org.apache.stanbol.contenthub.store.solr.manager.SolrCoreManager;
+import org.apache.stanbol.enhancer.ldpath.EnhancerLDPath;
+import org.apache.stanbol.enhancer.ldpath.backend.ContentItemBackend;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
 import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
 import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
 import org.apache.stanbol.entityhub.ldpath.backend.SiteManagerBackend;
@@ -50,6 +56,7 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import at.newmedialab.ldpath.LDPath;
 import at.newmedialab.ldpath.exception.LDPathParseException;
 import at.newmedialab.ldpath.model.programs.Program;
 
@@ -136,7 +143,7 @@ public class SemanticIndexManagerImpl im
 
         // Checks whether there is already a program with the same name
         if (nameProgramMap.containsKey(programName)) {
-            String msg = String.format("There is already an LDProgram with 
name :  " + programName);
+            String msg = String.format("There is already an LDProgram with 
name : %s", programName);
             logger.error(msg);
             throw new LDPathException(msg);
         }
@@ -193,23 +200,23 @@ public class SemanticIndexManagerImpl im
 
         return nameProgramMap.get(programName);
     }
-    
+
     @Override
     public Program<Object> getParsedProgramByName(String programName) {
         SiteManagerBackend backend = new 
SiteManagerBackend(referencedSiteManager);
         String ldPathProgram = getProgramByName(programName);
         ValueFactory vf = InMemoryValueFactory.getInstance();
         EntityhubLDPath ldPath = new EntityhubLDPath(backend, vf);
-       Program<Object> program = null;
+        Program<Object> program = null;
         try {
             program = 
ldPath.parseProgram(LDPathUtils.constructReader(ldPathProgram));
         } catch (LDPathParseException e) {
-               String msg = "Should never happen!!!!! Cannot parse the already 
stored LDPath program.";
+            String msg = "Should never happen!!!!! Cannot parse the already 
stored LDPath program.";
             logger.error(msg, e);
         } catch (LDPathException e) {
-               String msg = "Should never happen!!!!! Cannot parse the already 
stored LDPath program.";
+            String msg = "Should never happen!!!!! Cannot parse the already 
stored LDPath program.";
             logger.error(msg, e);
-               }
+        }
         return program;
     }
 
@@ -239,7 +246,7 @@ public class SemanticIndexManagerImpl im
     }
 
     @Override
-    public Map<String,Collection<?>> executeProgram(String programName, 
Set<String> contexts) throws LDPathException {
+    public Map<String,Collection<?>> executeProgram(String programName, 
Set<String> contexts, ContentItem ci) throws LDPathException {
         Map<String,Collection<?>> results = new 
HashMap<String,Collection<?>>();
         SiteManagerBackend backend = new 
SiteManagerBackend(referencedSiteManager);
         String ldPathProgram = getProgramByName(programName);
@@ -260,6 +267,7 @@ public class SemanticIndexManagerImpl im
             while (fieldNames.hasNext()) {
                 String fieldName = fieldNames.next();
                 Iterator<Object> valueIterator = representation.get(fieldName);
+                if (!valueIterator.hasNext()) continue;
                 Set<Object> values = new HashSet<Object>();
                 while (valueIterator.hasNext()) {
                     values.add(valueIterator.next());
@@ -276,6 +284,30 @@ public class SemanticIndexManagerImpl im
                 }
             }
         }
+
+        // execute the LDPath on the given ContentItem
+        ContentItemBackend contentItemBackend = new ContentItemBackend(ci, 
true);
+        LDPath<Resource> resourceLDPath = new 
LDPath<Resource>(contentItemBackend, EnhancerLDPath.getConfig());
+        Program<Resource> resourceProgram;
+        try {
+            resourceProgram = resourceLDPath.parseProgram(new 
StringReader(ldPathProgram));
+            Map<String,Collection<?>> ciBackendResults = 
resourceProgram.execute(contentItemBackend,
+                ci.getUri());
+            for (Entry<String,Collection<?>> result : 
ciBackendResults.entrySet()) {
+                if (result.getValue() == null || result.getValue().isEmpty()) 
continue;
+                if (results.containsKey(result.getKey())) {
+                    @SuppressWarnings("unchecked")
+                    Collection<Object> resultsValue = (Collection<Object>) 
results.get(result.getKey());
+                    resultsValue.addAll(result.getValue());
+                } else {
+                    results.put(result.getKey(), result.getValue());
+                }
+
+            }
+        } catch (LDPathParseException e) {
+            logger.error("Failed to create Program<Resource> from the LDPath 
program", e);
+        }
+
         return results;
     }
 }

Modified: stanbol/trunk/contenthub/store/solr/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/contenthub/store/solr/pom.xml?rev=1414111&r1=1414110&r2=1414111&view=diff
==============================================================================
--- stanbol/trunk/contenthub/store/solr/pom.xml (original)
+++ stanbol/trunk/contenthub/store/solr/pom.xml Tue Nov 27 10:36:32 2012
@@ -71,12 +71,6 @@
       <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
       <version>0.10.0-SNAPSHOT</version>
     </dependency>
-    <!-- Needed 0.10.0-SNAPSHOT version for InMemoryBlob -->
-    <dependency>
-      <groupId>org.apache.stanbol</groupId>
-      <artifactId>org.apache.stanbol.enhancer.core</artifactId>
-      <version>0.10.0-SNAPSHOT</version>
-    </dependency>
     <dependency>
       <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.commons.solr.core</artifactId>


Reply via email to