You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2013/11/27 14:32:52 UTC
svn commit: r1546029 - in
/stanbol/trunk/enhancement-engines/dereference/entityhub: ./ src/
src/license/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/stanbol/
src/main/java/org/apache/stanbol/enhancer/ ...
Author: rwesten
Date: Wed Nov 27 13:32:52 2013
New Revision: 1546029
URL: http://svn.apache.org/r1546029
Log:
STANBOL-1223: First implementation of an Dereferencer Engine for the Entityhub
Added:
stanbol/trunk/enhancement-engines/dereference/entityhub/ (with props)
stanbol/trunk/enhancement-engines/dereference/entityhub/pom.xml
stanbol/trunk/enhancement-engines/dereference/entityhub/src/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/license/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/license/THIRD-PARTY.properties
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferencer.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SiteDereferencer.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SitesDereferencer.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/metatype/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/metatype/metatype.properties
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/org/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/org/apache/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/org/apache/stanbol/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/org/apache/stanbol/enhancer/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/org/apache/stanbol/enhancer/engines/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/resources/
stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/resources/log4j.properties
Propchange: stanbol/trunk/enhancement-engines/dereference/entityhub/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Nov 27 13:32:52 2013
@@ -0,0 +1,7 @@
+target
+
+.project
+
+.classpath
+
+.settings
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/pom.xml?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/pom.xml (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/pom.xml Wed Nov 27 13:32:52 2013
@@ -0,0 +1,121 @@
+<?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>apache-stanbol-enhancement-engines</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.engines.dereference.entityhub</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Stanbol Enhancement Engine : Entityhub Dereference</name>
+ <description>
+ Dereferences Entities referenced by fise:entity-reference properties by
+ using the Stanbol Entityhub.
+ </description>
+
+ <inceptionYear>2013</inceptionYear>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/enhancement-engines/dereference/entityhub
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/enhancement-engines/dereference/entityhub
+ </developerConnection>
+ <url>http://stanbol.apache.org/</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.stanbol.enhancer.engines.dereference;version=${project.version}; provide:=true,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.stanbol.enhancer.engines.dereference.entityhub;version=${project.version}
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency> <!-- for parsing configs using namespace prefixes -->
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.commons.namespaceprefix.service</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.engines.dereference.core</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency> <!-- field mapping support -->
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.core</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency> <!-- ldpath support -->
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.ldpath</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency> <!-- converting Representations to RDF triples -->
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.model.clerezza</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/license/THIRD-PARTY.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/license/THIRD-PARTY.properties?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/license/THIRD-PARTY.properties (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/license/THIRD-PARTY.properties Wed Nov 27 13:32:52 2013
@@ -0,0 +1,24 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - Apache Software License
+# - Apache Software License, Version 2.0
+# - BSD License
+# - Common Development And Distribution License (CDDL), Version 1.0
+# - Common Development And Distribution License (CDDL), Version 1.1
+# - Common Public License, Version 1.0
+# - Eclipse Public License, Version 1.0
+# - GNU General Public License (GPL), Version 2 with classpath exception
+# - GNU Lesser General Public License (LGPL)
+# - GNU Lesser General Public License (LGPL), Version 2.1
+# - ICU License
+# - MIT License
+# - New BSD License
+# - Public Domain License
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Tue Jul 23 16:38:33 CEST 2013
+org.osgi--org.osgi.compendium--4.1.0=The Apache Software License, Version 2.0
+org.osgi--org.osgi.core--4.1.0=The Apache Software License, Version 2.0
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferenceEngine.java Wed Nov 27 13:32:52 2013
@@ -0,0 +1,246 @@
+/*
+* 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.enhancer.engines.dereference.entityhub;
+
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.DEREFERENCE_ENTITIES_FIELDS;
+import static org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants.DEREFERENCE_ENTITIES_LDPATH;
+import static org.apache.stanbol.enhancer.servicesapi.EnhancementEngine.PROPERTY_NAME;
+import static org.osgi.framework.Constants.SERVICE_RANKING;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+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.ReferenceCardinality;
+import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceUtils;
+import org.apache.stanbol.enhancer.engines.dereference.EntityDereferenceEngine;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
+import org.apache.stanbol.enhancer.servicesapi.ServiceProperties;
+import org.apache.stanbol.entityhub.servicesapi.Entityhub;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ * The EntityhubLinkingEngine in NOT an {@link EnhancementEngine} but only an
+ * OSGI {@link Component} that allows to configure instances of the
+ * {@link EntityLinkingEngine} using an {@link SiteDereferencer} or
+ * {@link EntityhubDereferencer} to link entities.
+ * @author Rupert Westenthaler
+ *
+ */
+@Component(
+ configurationFactory = true,
+ policy = ConfigurationPolicy.REQUIRE, // the baseUri is required!
+ specVersion = "1.1",
+ metatype = true,
+ immediate = true,
+ inherit = true)
+@org.apache.felix.scr.annotations.Properties(value={
+ @Property(name=PROPERTY_NAME),
+ @Property(name=EntityhubDereferenceEngine.SITE_ID),
+ @Property(name=DEREFERENCE_ENTITIES_FIELDS,cardinality=Integer.MAX_VALUE,
+ value={"rdfs:comment","geo:lat","geo:long","foaf:depiction","dbp-ont:thumbnail"}),
+ @Property(name=DEREFERENCE_ENTITIES_LDPATH, cardinality=Integer.MAX_VALUE),
+ @Property(name=SERVICE_RANKING,intValue=0)
+})
+public class EntityhubDereferenceEngine implements ServiceTrackerCustomizer {
+
+ private final Logger log = LoggerFactory.getLogger(EntityhubDereferenceEngine.class);
+
+ @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY)
+ protected NamespacePrefixService prefixService;
+
+ /**
+ * The id of the Entityhub Site (Referenced or Managed Site) used for matching. <p>
+ * To match against the Entityhub use "entityhub" as value.
+ */
+ public static final String SITE_ID = "enhancer.engines.dereference.entityhub.siteId";
+
+
+ /**
+ * The engine initialised based on the configuration of this component
+ */
+ protected EntityDereferenceEngine entityDereferenceEngine;
+ protected Dictionary<String,Object> engineMetadata;
+ /**
+ * The service registration for the {@link #entityDereferenceEngine}
+ */
+ protected ServiceRegistration engineRegistration;
+ /**
+ * The EntitySearcher used for the {@link #entityDereferenceEngine}
+ */
+ private TrackingDereferencerBase<?> entityDereferencer;
+ int trackedServiceCount = 0;
+
+ /**
+ * The name of the reference site ('local' or 'entityhub') if the
+ * Entityhub is used for enhancing
+ */
+ protected String siteName;
+
+ private BundleContext bundleContext;
+
+ /**
+ * Default constructor as used by OSGI. This expects that
+ * {@link #activate(ComponentContext)} is called before usage
+ */
+ public EntityhubDereferenceEngine() {
+ }
+
+ @Activate
+ @SuppressWarnings("unchecked")
+ protected void activate(ComponentContext ctx) throws ConfigurationException {
+ Dictionary<String,Object> properties = ctx.getProperties();
+ bundleContext = ctx.getBundleContext();
+ log.info("> activate {}",getClass().getSimpleName());
+ //get the metadata later set to the enhancement engine
+ String engineName;
+ engineMetadata = new Hashtable<String,Object>();
+ Object value = properties.get(PROPERTY_NAME);
+ if(value == null || value.toString().isEmpty()){
+ throw new ConfigurationException(PROPERTY_NAME, "The EnhancementEngine name MUST BE configured!");
+ } else {
+ engineName = value.toString().trim();
+ }
+ log.debug(" - engineName: {}",engineName);
+ engineMetadata.put(PROPERTY_NAME, engineName);
+ value = properties.get(SERVICE_RANKING);
+ Integer serviceRanking = null;
+ if(value instanceof Number){
+ serviceRanking = ((Number)value).intValue();
+ } else if(value != null){
+ try {
+ serviceRanking = Integer.parseInt(value.toString());
+ } catch(NumberFormatException e){
+ throw new ConfigurationException(SERVICE_RANKING, "Parsed service ranking '"
+ + value + "' (type: " + value.getClass().getName()
+ + "' can not be converted to an integer value!", e);
+ }
+ } //else not defined
+ if(serviceRanking != null){
+ log.debug(" - service.ranking: {}", serviceRanking);
+ engineMetadata.put(Constants.SERVICE_RANKING, serviceRanking);
+ }
+ //parse the Entityhub Site used for dereferencing
+ value = properties.get(SITE_ID);
+ //init the EntitySource
+ if (value == null) {
+ siteName = "*"; //all referenced sites
+ } else {
+ siteName = value.toString();
+ }
+ if (siteName.isEmpty()) {
+ siteName = "*";
+ }
+ log.debug(" - siteName: {}", siteName);
+ //init the tracking entity searcher
+ trackedServiceCount = 0;
+ if(Entityhub.ENTITYHUB_IDS.contains(siteName.toLowerCase())){
+ log.info(" ... init Entityhub dereferencer");
+ entityDereferencer = new EntityhubDereferencer(bundleContext, this, null);
+ } else if(siteName.equals("*")){
+ log.info(" ... init dereferencer for all referenced sites");
+ entityDereferencer = new SitesDereferencer(bundleContext, this, null);
+ } else {
+ log.info(" ... init dereferencer for referenced site {}", siteName);
+ entityDereferencer = new SiteDereferencer(bundleContext,siteName, this, null);
+ }
+ //set the namespace prefix service to the dereferencer
+ entityDereferencer.setNsPrefixService(prefixService);
+ //now parse dereference field config
+ entityDereferencer.setDereferencedFields(
+ DereferenceUtils.parseDereferencedFieldsConfig(properties));
+ //create the engine
+ entityDereferencer.setLdPath(
+ DereferenceUtils.parseLdPathConfig(properties));
+ entityDereferenceEngine = new EntityDereferenceEngine(engineName, entityDereferencer);
+ //NOTE: registration of this instance as OSGI service is done as soon as the
+ // entityhub service backing the entityDereferencer is available.
+
+ //finally start tracking
+ entityDereferencer.open();
+
+ }
+ /**
+ * Deactivates this components.
+ */
+ @Deactivate
+ protected void deactivate(ComponentContext context) {
+ //* unregister service
+ ServiceRegistration reg = engineRegistration;
+ if(reg != null){
+ reg.unregister();
+ engineRegistration = null;
+ }
+ //* reset engine
+ entityDereferenceEngine = null;
+ engineMetadata = null;
+ //close the tracking EntitySearcher
+ entityDereferencer.close();
+ entityDereferencer = null;
+ }
+ @Override
+ public Object addingService(ServiceReference reference) {
+ BundleContext bc = this.bundleContext;
+ if(bc != null){
+ Object service = bc.getService(reference);
+ if(service != null){
+ if(trackedServiceCount == 0){
+ //register the service
+ engineRegistration = bc.registerService(
+ new String[]{EnhancementEngine.class.getName(),
+ ServiceProperties.class.getName()},
+ entityDereferenceEngine,
+ engineMetadata);
+
+ }
+ trackedServiceCount++;
+ }
+ return service;
+ } else {
+ return null;
+ }
+ }
+ @Override
+ public void modifiedService(ServiceReference reference, Object service) {
+ }
+
+ @Override
+ public void removedService(ServiceReference reference, Object service) {
+ BundleContext bc = this.bundleContext;
+ if(bc != null){
+ trackedServiceCount--;
+ if(trackedServiceCount == 0 && engineRegistration != null){
+ engineRegistration.unregister();
+ }
+ bc.ungetService(reference);
+ }
+ }
+}
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferencer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferencer.java?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferencer.java (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/EntityhubDereferencer.java Wed Nov 27 13:32:52 2013
@@ -0,0 +1,75 @@
+/*
+* 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.enhancer.engines.dereference.entityhub;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceException;
+import org.apache.stanbol.enhancer.engines.dereference.EntityDereferencer;
+import org.apache.stanbol.entityhub.ldpath.backend.EntityhubBackend;
+import org.apache.stanbol.entityhub.servicesapi.Entityhub;
+import org.apache.stanbol.entityhub.servicesapi.EntityhubException;
+import org.apache.stanbol.entityhub.servicesapi.model.Entity;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+
+/**
+ * {@link EntityDereferencer} implementation for the {@link Entityhub}
+ * @author Rupert Westenthaler
+ *
+ */
+public final class EntityhubDereferencer extends TrackingDereferencerBase<Entityhub> implements EntityDereferencer {
+
+ private final ExecutorService executorService;
+
+ public EntityhubDereferencer(BundleContext context, ExecutorService executorService) {
+ this(context,null,executorService);
+ }
+ public EntityhubDereferencer(BundleContext context, ServiceTrackerCustomizer customizer, ExecutorService executorService) {
+ super(context,Entityhub.class,null,customizer);
+ this.executorService = executorService;
+ }
+
+ @Override
+ protected Representation getRepresentation(Entityhub eh, String id, boolean offlineMode) throws EntityhubException {
+ Entity e = eh.getEntity(id);
+ return e == null ? null : e.getRepresentation();
+ }
+
+ @Override
+ public boolean supportsOfflineMode() {
+ return true; //the entityhub is always offline
+ }
+ @Override
+ public ExecutorService getExecutor() {
+ return executorService;
+ }
+
+ @Override
+ protected RDFBackend<Object> createRdfBackend(Entityhub service) {
+ return new EntityhubBackend(service);
+ }
+
+
+
+}
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SiteDereferencer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SiteDereferencer.java?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SiteDereferencer.java (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SiteDereferencer.java Wed Nov 27 13:32:52 2013
@@ -0,0 +1,75 @@
+/*
+* 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.enhancer.engines.dereference.entityhub;
+
+import java.util.Collections;
+import java.util.concurrent.ExecutorService;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceException;
+import org.apache.stanbol.entityhub.ldpath.backend.SiteBackend;
+import org.apache.stanbol.entityhub.servicesapi.Entityhub;
+import org.apache.stanbol.entityhub.servicesapi.EntityhubException;
+import org.apache.stanbol.entityhub.servicesapi.model.Entity;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.site.Site;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+
+public final class SiteDereferencer extends TrackingDereferencerBase<Site> {
+
+// private final Logger log = LoggerFactory.getLogger(SiteDereferencer.class);
+
+ private final String siteId;
+ private final ExecutorService executorService;
+
+ public SiteDereferencer(BundleContext context, String siteId, ExecutorService executorService){
+ this(context,siteId, null, executorService);
+ }
+ public SiteDereferencer(BundleContext context, String siteId, ServiceTrackerCustomizer customizer, ExecutorService executorService) {
+ super(context, Site.class,
+ Collections.singletonMap(SiteConfiguration.ID,siteId),
+ customizer);
+ this.siteId = siteId;
+ this.executorService = executorService;
+ }
+
+ @Override
+ public boolean supportsOfflineMode() {
+ Site site = getService();
+ //Do not throw an exception here if the site is not available. Just return false
+ return site == null ? false : site.supportsLocalMode();
+ }
+ @Override
+ public ExecutorService getExecutor() {
+ return executorService;
+ }
+
+ @Override
+ protected Representation getRepresentation(Site site, String id, boolean offlineMode) throws EntityhubException {
+ Entity entity = site.getEntity(id);
+ return entity == null ? null : entity.getRepresentation();
+ }
+ @Override
+ protected RDFBackend<Object> createRdfBackend(Site service) {
+ return new SiteBackend(service);
+ }
+
+}
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SitesDereferencer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SitesDereferencer.java?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SitesDereferencer.java (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/SitesDereferencer.java Wed Nov 27 13:32:52 2013
@@ -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.enhancer.engines.dereference.entityhub;
+
+import java.util.concurrent.ExecutorService;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceException;
+import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
+import org.apache.stanbol.entityhub.ldpath.backend.SiteManagerBackend;
+import org.apache.stanbol.entityhub.servicesapi.Entityhub;
+import org.apache.stanbol.entityhub.servicesapi.EntityhubException;
+import org.apache.stanbol.entityhub.servicesapi.model.Entity;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.site.SiteManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+
+public final class SitesDereferencer extends TrackingDereferencerBase<SiteManager> {
+
+// private final Logger log = LoggerFactory.getLogger(SiteDereferencer.class);
+
+ private final ExecutorService executorService;
+
+ public SitesDereferencer(BundleContext context, ExecutorService executorService){
+ this(context, null, executorService);
+ }
+ public SitesDereferencer(BundleContext context, ServiceTrackerCustomizer customizer, ExecutorService executorService) {
+ super(context, SiteManager.class, null, customizer);
+ this.executorService = executorService;
+ }
+
+ @Override
+ public boolean supportsOfflineMode() {
+ return true; //can not be determined here .. return true
+ }
+ @Override
+ public ExecutorService getExecutor() {
+ return executorService;
+ }
+
+ @Override
+ protected Representation getRepresentation(SiteManager sm, String id, boolean offlineMode) throws EntityhubException {
+ Entity entity = sm.getEntity(id);
+ return entity == null ? null : entity.getRepresentation();
+ }
+
+ @Override
+ protected RDFBackend<Object> createRdfBackend(SiteManager service) {
+ return new SiteManagerBackend(service);
+ }
+
+}
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/java/org/apache/stanbol/enhancer/engines/dereference/entityhub/TrackingDereferencerBase.java Wed Nov 27 13:32:52 2013
@@ -0,0 +1,410 @@
+/*
+* 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.enhancer.engines.dereference.entityhub;
+
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.commons.lang.StringUtils;
+import org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceConstants;
+import org.apache.stanbol.enhancer.engines.dereference.DereferenceException;
+import org.apache.stanbol.enhancer.engines.dereference.EntityDereferencer;
+import org.apache.stanbol.entityhub.core.mapping.DefaultFieldMapperImpl;
+import org.apache.stanbol.entityhub.core.mapping.FieldMappingUtils;
+import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
+import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
+import org.apache.stanbol.entityhub.ldpath.backend.AbstractBackend;
+import org.apache.stanbol.entityhub.model.clerezza.RdfReference;
+import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
+import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.EntityhubException;
+import org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapper;
+import org.apache.stanbol.entityhub.servicesapi.mapping.FieldMapping;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
+import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.programs.Program;
+/**
+ * Abstract super class for EntityDereferencer that need to track the OSGI service
+ * used to lookup Entities. Used by the {@link EntityhubDereferencer} and the
+ * {@link SiteDereferencer} implementation
+ * @author Rupert Westenthaler
+ *
+ */
+public abstract class TrackingDereferencerBase<T> implements EntityDereferencer {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private ServiceTracker searchServiceTracker;
+ protected BundleContext bundleContext;
+
+ protected final RdfValueFactory valueFactory = RdfValueFactory.getInstance();
+
+ protected Set<String> dereferencedFields;
+ private FieldMapper fieldMapper;
+
+ private NamespacePrefixService nsPrefixService;
+
+ private Program<Object> ldpathProgram;
+ /**
+ * Caches the {@link RDFBackend} for the last instance returned by
+ * {@link #getService()}.
+ */
+ private Map<T,RDFBackend<Object>> rdfBackendCache = new IdentityHashMap<T,RDFBackend<Object>>();
+
+ private final Class<T> serviceClass;
+ /**
+ * Creates a new instance for the parsed parameter
+ * @param context the BundleContexed used to create the {@link ServiceTracker}
+ * listening for the SearchService
+ * @param serviceClass
+ * @param filterEntries
+ */
+ protected TrackingDereferencerBase(BundleContext context, Class<T> serviceClass,
+ Map<String,String> filterEntries, ServiceTrackerCustomizer customizer){
+ this.bundleContext = context;
+ this.serviceClass = serviceClass;
+ //the fieldMapper allows to configure users fields that should be dereferenced
+ if(filterEntries == null || filterEntries.isEmpty()){
+ searchServiceTracker = new ServiceTracker(context, serviceClass.getName(), customizer);
+ } else {
+ StringBuffer filterString = new StringBuffer();
+ filterString.append(String.format("(&(objectclass=%s)",serviceClass.getName()));
+ for(Entry<String,String> filterEntry : filterEntries.entrySet()){
+ if(filterEntry.getKey() != null && !filterEntry.getKey().isEmpty() &&
+ filterEntry.getValue() != null && !filterEntry.getValue().isEmpty()){
+ filterString.append(String.format("(%s=%s)",
+ filterEntry.getKey(),filterEntry.getValue()));
+ } else {
+ throw new IllegalArgumentException("Illegal filterEntry "+filterEntry+". Both key and value MUST NOT be NULL nor emtpty!");
+ }
+ }
+ filterString.append(')');
+ Filter filter;
+ try {
+ filter = context.createFilter(filterString.toString());
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException(String.format(
+ "Unable to build Filter for '%s' (class=%s,filter=%s)",
+ filterString,serviceClass,filterEntries),e);
+ }
+ searchServiceTracker = new ServiceTracker(context, filter, customizer);
+ }
+ }
+ /**
+ * Setter for the {@link NamespacePrefixService}
+ * @param nsPrefixService
+ */
+ public void setNsPrefixService(NamespacePrefixService nsPrefixService) {
+ this.nsPrefixService = nsPrefixService;
+ }
+ /**
+ * Getter for the {@link NamespacePrefixService}
+ * @return
+ */
+ public NamespacePrefixService getNsPrefixService() {
+ return nsPrefixService;
+ }
+ /**
+ * Setter for the dereferenced fields
+ * @param dereferencedFields the set containing the fields that need to be
+ * dereferenced. If <code>null</code> or an empty set all fields will be
+ * dereferenced.
+ */
+ public void setDereferencedFields(List<String> dereferencedFields) {
+ if(dereferencedFields != null && !dereferencedFields.isEmpty()){
+ fieldMapper = new DefaultFieldMapperImpl(ValueConverterFactory.getDefaultInstance());
+ log.debug(" > Initialise configured field mappings");
+ for(String configuredMapping : dereferencedFields){
+ FieldMapping mapping = FieldMappingUtils.parseFieldMapping(configuredMapping,nsPrefixService);
+ if(mapping != null){
+ log.debug(" - add FieldMapping {}",mapping);
+ fieldMapper.addMapping(mapping);
+ } else if(configuredMapping != null && !configuredMapping.isEmpty()){
+ log.warn(" - unable to parse FieldMapping '{}'", configuredMapping);
+ }
+ }
+ } else {
+ fieldMapper = null;
+ }
+ }
+ /**
+ * Setter for the LDPath program used for dereferencing Entities
+ * @param ldpathProgramStr the LDPath program as String
+ * @throws ConfigurationException if parsing the LDPath program fails
+ */
+ public void setLdPath(String ldpathProgramStr) throws ConfigurationException {
+ if(ldpathProgramStr == null || StringUtils.isBlank(ldpathProgramStr)){
+ ldpathProgram = null;
+ } else { //validate the parsed LDPath program
+ //when this method is called the real RDFBackend will not be available.
+ //however we would like to parse/validate the parsed LDPath program
+ //So we will create a pseudo RDFBackend sufficient to be used with the
+ //parser
+ final RDFBackend<Object> parseBackend = new AbstractBackend() {
+ @Override
+ protected QueryResultList<String> query(FieldQuery query) throws EntityhubException {
+ throw new UnsupportedOperationException("Not expected to be called");
+ }
+ @Override
+ protected ValueFactory getValueFactory() {
+ return valueFactory;
+ }
+ @Override
+ protected Representation getRepresentation(String id) throws EntityhubException {
+ throw new UnsupportedOperationException("Not expected to be called");
+ }
+ @Override
+ protected FieldQuery createQuery() {
+ throw new UnsupportedOperationException("Not expected to be called");
+ }
+ };
+ //NOTE: calling execute(..) an this parseLdPath or even the
+ //ldpathProgram will result in UnsupportedOperationException
+ //but parsing is OK
+ EntityhubLDPath parseLdPath = new EntityhubLDPath(parseBackend, valueFactory);
+ try {
+ ldpathProgram = parseLdPath.parseProgram(new StringReader(ldpathProgramStr));
+ } catch (LDPathParseException e) {
+ log.error("Unable to parse LDPath pogram: \n {}", ldpathProgramStr);
+ throw new ConfigurationException(DereferenceConstants.DEREFERENCE_ENTITIES_LDPATH,
+ "Unable to parse configured LDPath program ", e);
+ }
+ //finally validate if all mappings of the programm do use a URI as key
+ for(at.newmedialab.ldpath.model.fields.FieldMapping<?,Object> mapping : ldpathProgram.getFields()) {
+ try {
+ new URI(mapping.getFieldName());
+ } catch (URISyntaxException e){
+ throw new ConfigurationException(DereferenceConstants.DEREFERENCE_ENTITIES_LDPATH,
+ "Parsed LDPath MUST use valid URIs as field names (invalid field name: '"
+ + mapping.getFieldName()+"' | selector: '"
+ + mapping.getSelector().getPathExpression(parseBackend)+"')!");
+ }
+ }
+ }
+ }
+ /**
+ * Getter for the set of dereferenced fields
+ * @return the dereferenced fields or an empty set if all fields are
+ * dereferenced.
+ */
+ public Set<String> getDereferencedFields() {
+ return dereferencedFields;
+ }
+
+ /**
+ * Starts the tracking by calling {@link ServiceTracker#open()}
+ */
+ public void open(){
+ searchServiceTracker.open();
+ }
+ /**
+ * Getter for the Service used to search for Entities. If the service is
+ * currently not available, than this method will return <code>null</code>
+ * @return The service of <code>null</code> if not available
+ */
+ @SuppressWarnings("unchecked") //type is ensured by OSGI
+ protected T getService(){
+ if(searchServiceTracker == null){
+ throw new IllegalStateException("This TrackingEntitySearcher is already closed!");
+ } else {
+ return (T) searchServiceTracker.getService();
+ }
+ }
+
+ @Override
+ public final boolean dereference(UriRef uri, MGraph graph, boolean offlineMode, Lock writeLock) throws DereferenceException {
+ T service = getService();
+ if(service == null){
+ throw new DereferenceException(uri, serviceClass.getClass().getSimpleName()
+ + "service is currently not available");
+ }
+ Representation rep;
+ try {
+ rep = getRepresentation(service, uri.getUnicodeString(), offlineMode);
+ } catch(EntityhubException e){
+ throw new DereferenceException(uri,e);
+ }
+ if(rep != null){
+ if(fieldMapper == null && ldpathProgram == null){
+ copyAll(uri, rep, graph, writeLock);
+ } else {
+ if(fieldMapper != null){
+ copyMapped(uri, rep, graph, writeLock);
+ }
+ if(ldpathProgram != null){
+ copyLdPath(uri, getRdfBackend(service), graph, writeLock);
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ /**
+ * Executes the {@link #ldpathProgram} using the parsed URI as context and
+ * writes the the results to the parsed Graph
+ * @param uri the context
+ * @param rdfBackend the RdfBackend the LDPath program is executed on
+ * @param graph the graph to store the results
+ * @param writeLock the write lock for the graph
+ * @throws DereferenceException on any {@link EntityhubException} while
+ * executing the LDPath program
+ */
+ protected void copyLdPath(UriRef uri, RDFBackend<Object> rdfBackend,
+ MGraph graph, Lock writeLock) throws DereferenceException {
+ //A RdfReference needs to be used as context
+ RdfReference context = valueFactory.createReference(uri);
+ //create the representation that stores results in an intermediate
+ //graph (we do not want partial results on an error
+ MGraph ldPathResults = new SimpleMGraph();
+ RdfRepresentation result = valueFactory.createRdfRepresentation(uri, ldPathResults);
+ //execute the LDPath Program and write results to the RDF Graph
+ try {
+ for(at.newmedialab.ldpath.model.fields.FieldMapping<?,Object> mapping : ldpathProgram.getFields()) {
+ Collection<?> values = mapping.getValues(rdfBackend, context);
+ if(values != null && !values.isEmpty()){
+ result.add(mapping.getFieldName(),values);
+ }
+ }
+ } catch (EntityhubException e){
+ throw new DereferenceException(uri, e);
+ }
+ if(!ldPathResults.isEmpty()){ //copy the resutls
+ writeLock.lock();
+ try {
+ graph.addAll(ldPathResults);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+ }
+ /**
+ * Getter for the {@link RDFBackend} for the parsed service. This tries to
+ * get the backend from {@link #rdfBackendCache}. If it is not yet created
+ * {@link #createRdfBackend(Object)} is called.
+ * @param service The Service to get the {@link RDFBackend} for.
+ * @return the {@link RDFBackend}.
+ */
+ protected final RDFBackend<Object> getRdfBackend(T service) {
+ RDFBackend<Object> rdfBackend = rdfBackendCache.get(service);
+ if(rdfBackend == null){
+ rdfBackend = createRdfBackend(service);
+ rdfBackendCache.clear(); //cache only a single service
+ rdfBackendCache.put(service, rdfBackend);
+ }
+ return rdfBackend;
+ }
+
+ /**
+ * Applies the field mappings to the representation and stores the results
+ * in the graph
+ * @param uri the uri of the entity to dereference
+ * @param rep the data for the entity as in the entityhub
+ * @param graph the graph to store the mapping results
+ * @param writeLock the write lock for the graph
+ */
+ private void copyMapped(UriRef uri, Representation rep, MGraph graph, Lock writeLock) {
+ writeLock.lock();
+ try {
+ RdfRepresentation clerezzaRep = valueFactory.createRdfRepresentation(uri, graph);
+ fieldMapper.applyMappings(rep, clerezzaRep, valueFactory);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+ /**
+ * Copies all data form the representation to the graph. This is used
+ * if no dereference rules are defined
+ * @param uri the uri of the entity to copy
+ * @param rep the {@link Representation} with the data of the entity
+ * @param graph the graph to copy the data
+ * @param writeLock the write lock for the graph
+ */
+ private void copyAll(UriRef uri, Representation rep, MGraph graph, Lock writeLock) {
+ writeLock.lock();
+ try {
+ if(rep instanceof RdfRepresentation){
+ graph.addAll(((RdfRepresentation)rep).getRdfGraph());
+ } else {
+ RdfRepresentation clerezzaRep = valueFactory.createRdfRepresentation(uri,graph);
+ //convert all values for all fields
+ for (Iterator<String> fields = rep.getFieldNames(); fields.hasNext();) {
+ String field = fields.next();
+ for (Iterator<Object> fieldValues = rep.get(field); fieldValues.hasNext();) {
+ clerezzaRep.add(field, fieldValues.next());
+ }
+ }
+ }
+ } finally {
+ writeLock.unlock();
+ }
+ }
+ /**
+ * provides the Representation for the parsed id
+ * @param id the id
+ * @param offlineMode off line mode state
+ * @return the Representation or <code>null</code> if not found
+ * @throws DereferenceException
+ */
+ protected abstract Representation getRepresentation(T service, String id, boolean offlineMode) throws EntityhubException;
+ /**
+ * Creates an RDFBackend for the parsed service
+ * @param service
+ * @return
+ */
+ protected abstract RDFBackend<Object> createRdfBackend(T service);
+ /**
+ * Closes the {@link ServiceTracker} used to track the service.
+ */
+ public void close(){
+ searchServiceTracker.close();
+ searchServiceTracker = null;
+ bundleContext = null;
+ }
+ @Override
+ protected void finalize() throws Throwable {
+ close();
+ super.finalize();
+ }
+
+}
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/main/resources/OSGI-INF/metatype/metatype.properties Wed Nov 27 13:32:52 2013
@@ -0,0 +1,40 @@
+# 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.
+
+stanbol.enhancer.engine.name.name=Name
+stanbol.enhancer.engine.name.description=The name of the enhancement engine as \
+used in the RESTful interface '/engine/<name>'
+
+service.ranking.name=Ranking
+service.ranking.description=If two enhancement engines with the same name are active the \
+one with the higher ranking will be used to process parsed content items.
+
+
+#===============================================================================
+#Properties and Options used to configure
+#===============================================================================
+enhancer.engines.dereference.fields.name=Dereferenced Fields
+enhancer.engines.dereference.fields.description=The fields that are dereferenced. \
+This engine supports the Entityhub FieldMapping syntax. Examples: 'foaf:*' will \
+dereference all FOAF namespace properties; 'rdfs:label > schema:name' will \
+dereference values of rdfs:label and copy them to schema:name; \
+'rdfs:label | @=en' will just dereference English language literals of rdfs:label.
+
+enhancer.engines.dereference.ldpath.name=Dereference LD Path
+enhancer.engines.dereference.ldpath.description=Allows to use LD Path to specify \
+information to be included for dereferenced entities. This allows for sophisticated \
+dereference rules. As an example 'schema:name = .[rdf:type is foaf:Person]/fn:concat(\
+foaf:given," ",foaf:surname)' would construct the schema:name value by concatenation \
+of the foaf:given and foaf:surname if the entity is of type foaf:Person.
Added: stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/resources/log4j.properties?rev=1546029&view=auto
==============================================================================
--- stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/resources/log4j.properties (added)
+++ stanbol/trunk/enhancement-engines/dereference/entityhub/src/test/resources/log4j.properties Wed Nov 27 13:32:52 2013
@@ -0,0 +1,24 @@
+# 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.
+
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+log4j.logger.org.apache.stanbol.enhancer.engines.keywordextraction=DEBUG
\ No newline at end of file