Author: rwesten
Date: Thu Sep 22 07:19:48 2011
New Revision: 1173972

URL: http://svn.apache.org/viewvc?rev=1173972&view=rev
Log:
Forgot this folder in my last commit

Added:
    
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/ClasspathDataFileProvider.java
   (with props)
    
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/MockComponentContext.java
   (with props)
    
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/TestSearcherImpl.java
   (with props)

Added: 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/ClasspathDataFileProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/ClasspathDataFileProvider.java?rev=1173972&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/ClasspathDataFileProvider.java
 (added)
+++ 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/ClasspathDataFileProvider.java
 Thu Sep 22 07:19:48 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.keywordextraction.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import 
org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** DataFileProvider that looks in our class resources */
+public class ClasspathDataFileProvider implements DataFileProvider {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    public static final String RESOURCE_BASE_PATH = 
"org/apache/stanbol/data/opennlp/";
+    
+    private final String symbolicName;
+    
+    public ClasspathDataFileProvider(String bundleSymbolicName) {
+        symbolicName = bundleSymbolicName;
+    }
+    
+    @Override
+    public InputStream getInputStream(String bundleSymbolicName,
+            String filename, Map<String, String> comments) 
+    throws IOException {
+        //If the symbolic name is not null check that is equals to the symbolic
+        //name used to create this classpath data file provider
+        if(bundleSymbolicName != null && 
!symbolicName.equals(bundleSymbolicName)) {
+            log.debug("Requested bundleSymbolicName {} does not match mine 
({}), request ignored",
+                    bundleSymbolicName, symbolicName);
+            return null;
+        }
+        
+        // load default OpenNLP models from classpath (embedded in the 
defaultdata bundle)
+        final String resourcePath = RESOURCE_BASE_PATH + filename;
+        final InputStream in = 
getClass().getClassLoader().getResourceAsStream(resourcePath);
+        log.debug("Resource {} found: {}", (in == null ? "NOT" : ""), 
resourcePath);
+        
+        // Returning null is fine - if we don't have the data file, another
+        // provider might supply it
+        return in;
+    }
+}

Propchange: 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/ClasspathDataFileProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/MockComponentContext.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/MockComponentContext.java?rev=1173972&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/MockComponentContext.java
 (added)
+++ 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/MockComponentContext.java
 Thu Sep 22 07:19:48 2011
@@ -0,0 +1,199 @@
+/*
+ * 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.keywordextraction.impl;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.ComponentInstance;
+
+public class MockComponentContext implements ComponentContext {
+
+    protected final Dictionary<String, Object> properties;
+
+    public MockComponentContext() {
+        properties = new Hashtable<String, Object>();
+    }
+
+    public MockComponentContext(Dictionary<String, Object> properties) {
+        this.properties = properties;
+    }
+
+    public void disableComponent(String name) {
+    }
+
+    public void enableComponent(String name) {
+    }
+
+    public BundleContext getBundleContext() {
+        return new BundleContext() {
+
+            @Override
+            public boolean ungetService(ServiceReference reference) {
+                return false;
+            }
+
+            @Override
+            public void removeServiceListener(ServiceListener listener) {
+            }
+
+            @Override
+            public void removeFrameworkListener(FrameworkListener listener) {
+            }
+
+            @Override
+            public void removeBundleListener(BundleListener listener) {
+            }
+
+            @Override
+            public ServiceRegistration registerService(String clazz,
+                    Object service, Dictionary properties) {
+                return null;
+            }
+
+            @Override
+            public ServiceRegistration registerService(String[] clazzes,
+                    Object service, Dictionary properties) {
+                return null;
+            }
+
+            @Override
+            public Bundle installBundle(String location, InputStream input)
+                    throws BundleException {
+                return null;
+            }
+
+            @Override
+            public Bundle installBundle(String location) throws 
BundleException {
+                return null;
+            }
+
+            @Override
+            public ServiceReference[] getServiceReferences(String clazz,
+                    String filter) throws InvalidSyntaxException {
+                return null;
+            }
+
+            @Override
+            public ServiceReference getServiceReference(String clazz) {
+                return null;
+            }
+
+            @Override
+            public Object getService(ServiceReference reference) {
+                return null;
+            }
+
+            @Override
+            public String getProperty(String key) {
+                return null;
+            }
+
+            @Override
+            public File getDataFile(String filename) {
+                return new File(System.getProperty("java.io.tmpdir"));
+            }
+
+            @Override
+            public Bundle[] getBundles() {
+                return null;
+            }
+
+            @Override
+            public Bundle getBundle(long id) {
+                return null;
+            }
+
+            @Override
+            public Bundle getBundle() {
+                return null;
+            }
+
+            @Override
+            public ServiceReference[] getAllServiceReferences(String clazz,
+                    String filter) throws InvalidSyntaxException {
+                return null;
+            }
+
+            @Override
+            public Filter createFilter(String filter)
+                    throws InvalidSyntaxException {
+                return null;
+            }
+
+            @Override
+            public void addServiceListener(ServiceListener listener,
+                    String filter) throws InvalidSyntaxException {
+
+            }
+
+            @Override
+            public void addServiceListener(ServiceListener listener) {
+            }
+
+            @Override
+            public void addFrameworkListener(FrameworkListener listener) {
+            }
+
+            @Override
+            public void addBundleListener(BundleListener listener) {
+            }
+        };
+    }
+
+    public ComponentInstance getComponentInstance() {
+        return null;
+    }
+
+    public Dictionary<String, Object> getProperties() {
+        return properties;
+    }
+
+    public ServiceReference getServiceReference() {
+        return null;
+    }
+
+    public Bundle getUsingBundle() {
+        return null;
+    }
+
+    public Object locateService(String name) {
+        return null;
+    }
+
+    public Object locateService(String name, ServiceReference reference) {
+        return null;
+    }
+
+    public Object[] locateServices(String name) {
+        return null;
+    }
+
+}

Propchange: 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/MockComponentContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/TestSearcherImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/TestSearcherImpl.java?rev=1173972&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/TestSearcherImpl.java
 (added)
+++ 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/TestSearcherImpl.java
 Thu Sep 22 07:19:48 2011
@@ -0,0 +1,85 @@
+package org.apache.stanbol.enhancer.engines.keywordextraction.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import opennlp.tools.tokenize.Tokenizer;
+
+import 
org.apache.stanbol.enhancer.engines.keywordextraction.linking.EntitySearcher;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.Text;
+
+public class TestSearcherImpl implements EntitySearcher {
+
+    private final String nameField;
+    private final Tokenizer tokenizer;
+    
+    private SortedMap<String,Collection<Representation>> data = new 
TreeMap<String,Collection<Representation>>(String.CASE_INSENSITIVE_ORDER);
+    private Map<String,Representation> entities = new 
HashMap<String,Representation>();
+
+    
+    public TestSearcherImpl(String nameField, Tokenizer tokenizer) {
+        this.nameField = nameField;
+        this.tokenizer = tokenizer;
+    }
+    
+    
+    public void addEntity(Representation rep){
+        entities.put(rep.getId(), rep);
+        Iterator<Text> labels = rep.getText(nameField);
+        while(labels.hasNext()){
+            Text label = labels.next();
+            for(String token : tokenizer.tokenize(label.getText())){
+                Collection<Representation> values = data.get(token);
+                if(values == null){
+                    values = new ArrayList<Representation>();
+                    data.put(label.getText(), values);
+                }
+                values.add(rep);
+            }
+        }
+        
+    }
+    
+    @Override
+    public Representation get(String id, Set<String> includeFields) throws 
IllegalStateException {
+        return entities.get(id);
+    }
+
+    @Override
+    public Collection<? extends Representation> lookup(String field,
+                                           Set<String> includeFields,
+                                           List<String> search,
+                                           String... languages) throws 
IllegalStateException {
+        if(field.equals(nameField)){
+            //we do not need sorting
+            //Representation needs to implement equals, therefore results 
filters multiple matches
+            Set<Representation> results = new HashSet<Representation>();
+            for(String term : search){
+                //TODO: adding 'zzz' to the parsed term is no good solution for
+                //      searching ...
+                for(Collection<Representation> termResults : data.subMap(term, 
term+"zzz").values()){
+                    results.addAll(termResults);
+                }
+            }
+            return results;
+        } else {
+            throw new IllegalStateException("Lookup is only supported for the 
nameField '"+
+                nameField+"' parsed to the constructor");
+        }
+    }
+
+    @Override
+    public boolean supportsOfflineMode() {
+        return true;
+    }
+
+}

Propchange: 
incubator/stanbol/trunk/enhancer/engines/keywordextraction/src/test/java/org/apache/stanbol/enhancer/engines/keywordextraction/impl/TestSearcherImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to