ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1627794 - in /ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2: ae/ util/collection/
Date Fri, 26 Sep 2014 14:24:38 GMT
Author: seanfinan
Date: Fri Sep 26 14:24:38 2014
New Revision: 1627794

URL: http://svn.apache.org/r1627794
Log:
New CollectionMaps
LookupFactory

Added:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/ae/DictionaryLookupFactory.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreator.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreatorFactory.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/DefaultCollectionMap.java
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/EnumSetMap.java

Added: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/ae/DictionaryLookupFactory.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/ae/DictionaryLookupFactory.java?rev=1627794&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/ae/DictionaryLookupFactory.java
(added)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/ae/DictionaryLookupFactory.java
Fri Sep 26 14:24:38 2014
@@ -0,0 +1,39 @@
+package org.apache.ctakes.dictionary.lookup2.ae;
+
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.fit.factory.AnalysisEngineFactory;
+import org.apache.uima.resource.ResourceInitializationException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class DictionaryLookupFactory {
+
+   private DictionaryLookupFactory() {
+   }
+
+   public static AnalysisEngineDescription createUmlsDictionaryLookupDescription()
+         throws ResourceInitializationException {
+      return AnalysisEngineFactory.createEngineDescription( DefaultJCasTermAnnotator.class,
+            JCasTermAnnotator.DICTIONARY_DESCRIPTOR_KEY,
+            "org/apache/ctakes/dictionary/lookup/fast/cTakesHsql.xml" );
+   }
+
+   public static AnalysisEngineDescription createCustomDictionaryLookupDescription( final
String dictionaryDescriptor )
+         throws ResourceInitializationException {
+      if ( !(new File( dictionaryDescriptor )).exists() ) {
+         throw new ResourceInitializationException( new FileNotFoundException( dictionaryDescriptor
) );
+      }
+      return AnalysisEngineFactory.createEngineDescription( DefaultJCasTermAnnotator.class,
+            JCasTermAnnotator.DICTIONARY_DESCRIPTOR_KEY,
+            dictionaryDescriptor );
+   }
+
+
+}

Added: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreator.java?rev=1627794&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreator.java
(added)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreator.java
Fri Sep 26 14:24:38 2014
@@ -0,0 +1,17 @@
+package org.apache.ctakes.dictionary.lookup2.util.collection;
+
+import java.util.Collection;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+public interface CollectionCreator<V, T extends Collection<V>> {
+
+   public T createCollection();
+
+   public T createCollection( int size );
+
+
+}

Added: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreatorFactory.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreatorFactory.java?rev=1627794&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreatorFactory.java
(added)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionCreatorFactory.java
Fri Sep 26 14:24:38 2014
@@ -0,0 +1,46 @@
+package org.apache.ctakes.dictionary.lookup2.util.collection;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class CollectionCreatorFactory {
+
+   private CollectionCreatorFactory() {
+   }
+
+   static public <V> CollectionCreator<V, Set<V>> createSetCreator() {
+      return new CollectionCreator<V, Set<V>>() {
+         @Override
+         public Set<V> createCollection() {
+            return new HashSet<>();
+         }
+
+         @Override
+         public Set<V> createCollection( final int size ) {
+            return new HashSet<>( size );
+         }
+      };
+   }
+
+   static public <V> CollectionCreator<V, List<V>> createListCreator()
{
+      return new CollectionCreator<V, List<V>>() {
+         @Override
+         public List<V> createCollection() {
+            return new ArrayList<>();
+         }
+
+         @Override
+         public List<V> createCollection( final int size ) {
+            return new ArrayList<>( size );
+         }
+      };
+   }
+
+}

Added: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/DefaultCollectionMap.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/DefaultCollectionMap.java?rev=1627794&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/DefaultCollectionMap.java
(added)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/DefaultCollectionMap.java
Fri Sep 26 14:24:38 2014
@@ -0,0 +1,276 @@
+package org.apache.ctakes.dictionary.lookup2.util.collection;
+
+import java.util.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class DefaultCollectionMap<K, V, T extends Collection<V>> implements
CollectionMap<K, V, T> {
+
+   private final Map<K, T> _delegate;
+   private final CollectionCreator<V, T> _collectionCreator;
+   private final T EMPTY_COLLECTION;
+
+   public DefaultCollectionMap( final Map<K, T> delegate, final CollectionCreator<V,
T> collectionCreator ) {
+      _delegate = delegate;
+      _collectionCreator = collectionCreator;
+      EMPTY_COLLECTION = collectionCreator.createCollection();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Iterator<Entry<K, T>> iterator() {
+      final Iterator<Map.Entry<K, T>> setIterator = _delegate.entrySet().iterator();
+      return new Iterator<Map.Entry<K, T>>() {
+         public boolean hasNext() {
+            return setIterator.hasNext();
+         }
+
+         public Map.Entry<K, T> next() {
+            final Map.Entry<K, T> next = setIterator.next();
+            return new Map.Entry<K, T>() {
+               public K getKey() {
+                  return next.getKey();
+               }
+
+               public T getValue() {
+                  return next.getValue();
+               }
+
+               public T setValue( final T value ) {
+                  return null;
+               }
+            };
+         }
+
+         public void remove() {
+         }
+      };
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<T> getAllCollections() {
+      return new HashSet<>( _delegate.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T getCollection( final K key ) {
+      final T collection = _delegate.get( key );
+      if ( collection != null ) {
+         return collection;
+      }
+      return EMPTY_COLLECTION;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T obtainCollection( final K key ) {
+      T collection = _delegate.get( key );
+      if ( collection == null ) {
+         collection = _collectionCreator.createCollection();
+         _delegate.put( key, collection );
+      }
+      return collection;
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      final T collection = _delegate.get( key );
+      return collection != null && collection.contains( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      T collection = _delegate.get( key );
+      if ( collection == null ) {
+         collection = _collectionCreator.createCollection();
+         _delegate.put( key, collection );
+      }
+      return collection.add( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      boolean placedAny = false;
+      for ( Map.Entry<K, V> entry : map.entrySet() ) {
+         final boolean placed = placeValue( entry.getKey(), entry.getValue() );
+         placedAny = placedAny || placed;
+      }
+      return placedAny;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void removeValue( final K key, final V value ) {
+      final T collection = _delegate.get( key );
+      if ( collection == null ) {
+         return;
+      }
+      collection.remove( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C values
) {
+      T collection = _delegate.get( key );
+      if ( collection == null ) {
+         collection = _collectionCreator.createCollection();
+         _delegate.put( key, collection );
+      }
+      final int oldSize = collection.size();
+      collection.addAll( values );
+      return collection.size() - oldSize;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      final T collection = _delegate.get( key );
+      if ( collection != null ) {
+         collection.clear();
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public int size() {
+      return _delegate.size();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean isEmpty() {
+      return _delegate.isEmpty();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsKey( final Object key ) {
+      return _delegate.containsKey( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final Object value ) {
+      return _delegate.containsValue( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T get( final Object key ) {
+      return _delegate.get( key );
+   }
+
+   // Modification Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T put( final K key, final T value ) {
+      return _delegate.put( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T remove( final Object key ) {
+      return _delegate.remove( key );
+   }
+
+
+   // Bulk Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void putAll( final Map<? extends K, ? extends T> map ) {
+      _delegate.putAll( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clear() {
+      _delegate.clear();
+   }
+
+
+   // Views
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<K> keySet() {
+      return _delegate.keySet();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<T> values() {
+      return _delegate.values();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<Map.Entry<K, T>> entrySet() {
+      return _delegate.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, T> toSimpleMap() {
+      return _delegate;
+   }
+
+
+}

Added: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/EnumSetMap.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/EnumSetMap.java?rev=1627794&view=auto
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/EnumSetMap.java
(added)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/EnumSetMap.java
Fri Sep 26 14:24:38 2014
@@ -0,0 +1,215 @@
+package org.apache.ctakes.dictionary.lookup2.util.collection;
+
+import java.util.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class EnumSetMap<K extends Enum<K>, V> implements CollectionMap<K,
V, Set<V>> {
+
+   private final CollectionMap<K, V, Set<V>> _delegate;
+
+
+   public EnumSetMap( final Class<K> enumType ) {
+      final EnumMap<K, Set<V>> enumMap = new EnumMap<>( enumType );
+      final CollectionCreator<V, Set<V>> creator = CollectionCreatorFactory.createSetCreator();
+      _delegate = new DefaultCollectionMap<>( enumMap, creator );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Iterator<Map.Entry<K, Set<V>>> iterator() {
+      return _delegate.iterator();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<Set<V>> getAllCollections() {
+      return new HashSet<>( _delegate.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> getCollection( final K key ) {
+      return _delegate.getCollection( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> obtainCollection( final K key ) {
+      return _delegate.obtainCollection( key );
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      return _delegate.containsValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      return _delegate.placeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      return _delegate.placeMap( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void removeValue( final K key, final V value ) {
+      _delegate.removeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C collection
) {
+      return _delegate.addAllValues( key, collection );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      _delegate.clearCollection( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public int size() {
+      return _delegate.size();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean isEmpty() {
+      return _delegate.isEmpty();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsKey( final Object key ) {
+      return _delegate.containsKey( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final Object value ) {
+      return _delegate.containsValue( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> get( final Object key ) {
+      return _delegate.get( key );
+   }
+
+   // Modification Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> put( final K key, final Set<V> value ) {
+      return _delegate.put( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> remove( final Object key ) {
+      return _delegate.remove( key );
+   }
+
+
+   // Bulk Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void putAll( final Map<? extends K, ? extends Set<V>> map ) {
+      _delegate.putAll( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clear() {
+      _delegate.clear();
+   }
+
+
+   // Views
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<K> keySet() {
+      return _delegate.keySet();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<Set<V>> values() {
+      return _delegate.values();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<Map.Entry<K, Set<V>>> entrySet() {
+      return _delegate.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, Set<V>> toSimpleMap() {
+      return _delegate;
+   }
+
+}



Mime
View raw message