You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2009/10/28 16:50:53 UTC

svn commit: r830647 - in /incubator/uima/sandbox/trunk/ConceptMapper: desc/analysis_engine/primitive/ docs/pdf/ src/main/java/org/apache/uima/conceptMapper/dictionaryCompiler/ src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/

Author: schor
Date: Wed Oct 28 15:50:52 2009
New Revision: 830647

URL: http://svn.apache.org/viewvc?rev=830647&view=rev
Log:
UIMA-1639 https://issues.apache.org/jira/browse/UIMA-1639
Applied patch after deleting last segment which wasn't applying, and then added new class using the other attachment to this Jira, which the last segment was trying to do.

Added:
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesRoot.java
Removed:
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesFactory.java
Modified:
    incubator/uima/sandbox/trunk/ConceptMapper/desc/analysis_engine/primitive/ConceptMapperOffsetTokenizer.xml
    incubator/uima/sandbox/trunk/ConceptMapper/docs/pdf/ConceptMapperAnnotatorUserGuide.pdf
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/dictionaryCompiler/CompileDictionary.java
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/CompiledDictionaryResource_impl.java
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource.java
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource_impl.java
    incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java

Modified: incubator/uima/sandbox/trunk/ConceptMapper/desc/analysis_engine/primitive/ConceptMapperOffsetTokenizer.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/desc/analysis_engine/primitive/ConceptMapperOffsetTokenizer.xml?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/desc/analysis_engine/primitive/ConceptMapperOffsetTokenizer.xml (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/desc/analysis_engine/primitive/ConceptMapperOffsetTokenizer.xml Wed Oct 28 15:50:52 2009
@@ -361,7 +361,7 @@
 				<name>TokenizerDescriptorPath</name>
 				<value>
 					<string>
-						/OtherStuff/IBM/eclipse-apacheuima/conceptMapper/descriptors/analysis_engine/primitive/OffsetTokenizer.xml
+						/OtherStuff/IBM/eclipse-UIMAsandbox/ConceptMapper/desc/analysis_engine/primitive/OffsetTokenizer.xml
 					</string>
 				</value>
 			</nameValuePair>

Modified: incubator/uima/sandbox/trunk/ConceptMapper/docs/pdf/ConceptMapperAnnotatorUserGuide.pdf
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/docs/pdf/ConceptMapperAnnotatorUserGuide.pdf?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/dictionaryCompiler/CompileDictionary.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/dictionaryCompiler/CompileDictionary.java?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/dictionaryCompiler/CompileDictionary.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/dictionaryCompiler/CompileDictionary.java Wed Oct 28 15:50:52 2009
@@ -30,11 +30,20 @@
   private static final String DICTIONARY_RESOURCE_NAME = "/DictionaryFile";
 
   public static void main(String[] args) throws Exception {
+    String dictionaryResourceName = DICTIONARY_RESOURCE_NAME;
+    if (args.length == 2) {
+      // do nothing
+    } else if (args.length == 3) {
+      dictionaryResourceName = args[2];
+    } else {
+      usage();
+      System.exit(17);
+    }
     AnalysisEngineDescription conceptMapperDesc = UIMAFramework.getXMLParser()
             .parseAnalysisEngineDescription(new XMLInputSource(args[0]));
     AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(conceptMapperDesc);
     DictionaryResource_impl dict = (DictionaryResource_impl) ae.getResourceManager().getResource(
-            DICTIONARY_RESOURCE_NAME);
+    		dictionaryResourceName);
 
     FileOutputStream output = new FileOutputStream(args[1]);
     dict.serializeEntries(output);
@@ -44,4 +53,19 @@
     // probably because CPM threads are alive?
     System.exit(0);
   }
+  
+  public static class ClassNameFinder extends SecurityManager{
+    public String getClassName(){
+      return getClassContext()[1].getName();
+    }
+  }
+
+  public static String getCurClassName(){
+    return (new ClassNameFinder()).getClassName();
+  }
+
+  public static void usage ()
+  {
+    System.out.println("USAGE: " + getCurClassName() + ": <pathToDescriptor> <outputFileName> [<resourceName>]");
+  }
 }

Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/CompiledDictionaryResource_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/CompiledDictionaryResource_impl.java?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/CompiledDictionaryResource_impl.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/CompiledDictionaryResource_impl.java Wed Oct 28 15:50:52 2009
@@ -38,6 +38,7 @@
    * of every entry in the specified dictionary.
    */
   protected Hashtable<String, DictEntriesByLength> dictImpl;
+  protected EntryPropertiesRoot entryPropertiesRoot;
 
   public DictionaryResource newDictionaryResource(int initialSize) {
     throw new UnsupportedOperationException();
@@ -59,6 +60,7 @@
   public void load(DataResource data) throws ResourceInitializationException {
     try {
       ObjectInputStream ois = new ObjectInputStream(data.getInputStream());
+      entryPropertiesRoot = (EntryPropertiesRoot) ois.readObject();
       dictImpl = (Hashtable) ois.readObject();
       ois.close();
     } catch (IOException e) {
@@ -79,4 +81,8 @@
     throw new UnsupportedOperationException();
   }
 
+  public EntryPropertiesRoot getEntryPropertiesRoot() {
+	return entryPropertiesRoot;
+  }
+
 }
\ No newline at end of file

Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource.java?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource.java Wed Oct 28 15:50:52 2009
@@ -37,6 +37,8 @@
 
   public DictionaryResource newDictionaryResource(int initialSize);
 
+  public EntryPropertiesRoot getEntryPropertiesRoot ();
+  
   public interface DictEntriesByLength extends Serializable {
     public DictEntries getEntries(int length);
 

Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource_impl.java?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource_impl.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryResource_impl.java Wed Oct 28 15:50:52 2009
@@ -60,7 +60,7 @@
  */
 
 public class DictionaryResource_impl implements DictionaryResource, SharedResourceObject {
-  /** Dictionary file loader. Uses an XML parser. */
+/** Dictionary file loader. Uses an XML parser. */
   protected DictLoader dictLoader;
 
   /**
@@ -68,6 +68,8 @@
    * of every entry in the specified dictionary.
    */
   protected Hashtable<String, DictEntriesByLength> dictImpl;
+  
+  protected EntryPropertiesRoot entryPropertiesRoot;
 
   /** Initial size of <code>dict</code> */
   protected static final int NumOfInitialDictEntries = 500000;
@@ -266,13 +268,14 @@
       XMLParserName = (String) aContext.getConfigParameterValue(PARAM_XML_PARSER);
       
       String [] entryPropertyNames = (String []) aContext.getConfigParameterValue(PARAM_ATTRIBUTE_LIST);
+      entryPropertiesRoot = new EntryPropertiesRoot(entryPropertyNames);
       // System.out.print ("Loading Dictionary: '" + dictLoader.dataResource.getUri().toString() +
       // "'...");
       // System.out.print ("Loading Dictionary...");
       logger.logInfo("Loading Dictionary...");
       dictLoader.setDictionary(dictStream, NumOfInitialDictEntries, tokenAnnotationName,
               tokenTypeFeatureName, tokenClassFeatureName, tokenizerDescriptor, tokenFilter,
-              tokenNormalizer, langID, entryPropertyNames);
+              tokenNormalizer, langID, entryPropertiesRoot);
       logger.logInfo("...done");
       // System.out.println ("done");
       // System.err.println("NEW DICT:\n" + toString());
@@ -500,14 +503,14 @@
           result.append (element);
           }
       result.append ("''>");
-      
-      for (String propertyName : EntryPropertiesFactory.propertyNames())
+      /* TODO
+      for (String propertyName : entryPropertiesRoot.propertyNames())
       {
           result.append("<property name='" + propertyName.toString() + "'>");
           String item = getProperties().getProperty(propertyName);
           result.append(item);
           result.append("</property>\n");
-      }
+      }*/
       result.append("</DictEntry>\n");
       return result.toString();
 
@@ -627,7 +630,7 @@
 
     private TokenNormalizer tokenNormalizer;
     
-    private EntryPropertiesFactory entryPropertiesFactory;
+    private EntryPropertiesRoot entryPropertiesRoot;
 
     /**
      * needed to access input stream, since cannot load external dict resource until TAE config
@@ -695,14 +698,14 @@
       this.tokenNormalizer = tokenNormalizer;
     }
 
-    protected void setPropertiesFactory (EntryPropertiesFactory factory)
+    protected void setEntryPropertiesRoot (EntryPropertiesRoot entryPropertiesRoot)
     {
-    	this.entryPropertiesFactory = factory;
+    	this.entryPropertiesRoot = entryPropertiesRoot;
     }
 
-    protected EntryPropertiesFactory getPropertiesFactory ()
+    protected EntryPropertiesRoot getPropertiesRoot ()
     {
-    	return entryPropertiesFactory;
+    	return entryPropertiesRoot;
     }
     
     protected TokenNormalizer getTokenNormalizer() {
@@ -737,7 +740,7 @@
       if (raw.equals(token_elem)) { // starting new token entry
         if (attrs != null) {
 
-        	props = getPropertiesFactory().newEntryProperties();
+        	props = getPropertiesRoot().newEntryProperties();
 			int attrCount = attrs.getLength();
 			for (int i = 0; i < attrCount; i++) {
 				props.setProperty(attrs.getQName(i), convertEntities(attrs.getValue(i)));
@@ -925,7 +928,7 @@
      */
     public void setDictionary(InputStream dictStream, int initialDictEntries,
             String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
-            String tokenizerDescriptor, TokenFilter tokenFilter, TokenNormalizer tokenNormalizer, String langID, String [] entryPropertyNames)
+            String tokenizerDescriptor, TokenFilter tokenFilter, TokenNormalizer tokenNormalizer, String langID, EntryPropertiesRoot entryPropertiesRoot)
             throws DictionaryLoaderException {
       term_cnt = 0;
       setTokenAnnotationName(tokenAnnotationName);
@@ -934,7 +937,7 @@
       setTokenNormalizer(tokenNormalizer);
       result = new Vector<DictionaryToken>();
 
-      setPropertiesFactory (EntryPropertiesFactory.create (entryPropertyNames));
+      setEntryPropertiesRoot (entryPropertiesRoot);
       
       getLogger().logInfo("Loading dictionary");
       try {
@@ -1007,8 +1010,13 @@
 
   public void serializeEntries(FileOutputStream output) throws IOException {
     ObjectOutputStream oos = new ObjectOutputStream(output);
+    oos.writeObject(this.entryPropertiesRoot);
     oos.writeObject(this.dictImpl);
     oos.close();
   }
 
+  public EntryPropertiesRoot getEntryPropertiesRoot() {
+	return entryPropertiesRoot;
+  }
+
 }
\ No newline at end of file

Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java?rev=830647&r1=830646&r2=830647&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java Wed Oct 28 15:50:52 2009
@@ -27,6 +27,7 @@
      */
     private static final long serialVersionUID = 1L;
 	private String [] properties;
+	private EntryPropertiesRoot entryPropertiesRoot;
 
 	/**
 	 * 
@@ -36,17 +37,19 @@
 	 * 
 	 * should only be called by factory
 	 */
-	public EntryProperties (EntryPropertiesFactory factory, int maxNumberOfProperties) throws NullPointerException
+	public EntryProperties (EntryPropertiesRoot root, int maxNumberOfProperties) throws NullPointerException
 	{
-		if (factory == null)
+		if (root == null)
 		{
-			throw new NullPointerException ("EntryProperties not initialized via EntryProperties.init()");
+			throw new NullPointerException ("EntryPropertiesRoot cannot be null");
 		}
+		entryPropertiesRoot = root;
 		properties = new String [maxNumberOfProperties];
 	}
 	
 	public EntryProperties (EntryProperties toCopyFrom)
 	{
+		entryPropertiesRoot = toCopyFrom.entryPropertiesRoot;
 		properties = toCopyFrom.properties.clone();
 	}
 	
@@ -56,7 +59,7 @@
 	}
 	
 	public String getProperty(String propertyName, String defaultValue) {
-		int propertyID = EntryPropertiesFactory.getPropertyID (propertyName);
+		int propertyID = entryPropertiesRoot.getPropertyID (propertyName);
 		if (propertyID < 0)
 		{
 			return defaultValue;
@@ -68,7 +71,7 @@
 	}
 
 	public void setProperty(String propertyName, String propertyValue) {
-		int propertyID = EntryPropertiesFactory.getPropertyID (propertyName);
+		int propertyID = entryPropertiesRoot.getPropertyID (propertyName);
 		if (propertyID < 0)
 		{
 			// do nothing

Added: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesRoot.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesRoot.java?rev=830647&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesRoot.java (added)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesRoot.java Wed Oct 28 15:50:52 2009
@@ -0,0 +1,68 @@
+/*
+ * 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.uima.conceptMapper.support.dictionaryResource;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+public class EntryPropertiesRoot implements Serializable {
+
+  /**
+   * 
+   */
+  private static final long serialVersionUID = -4158518283347402903L;
+  private String [] propertyNames = null;
+  
+  public EntryPropertiesRoot (String [] thePropertyNames)
+  {
+    if (propertyNames == null)
+    {
+      propertyNames = new String [thePropertyNames.length];
+      int i = 0;
+      for (String prop : thePropertyNames)
+      {
+        propertyNames[i] = prop;
+        i += 1;
+      }
+      Arrays.sort(propertyNames);
+    }
+  }
+
+  public String [] propertyNames ()
+  {
+    return propertyNames;
+  }
+  
+  public int getPropertyID(String propertyName) {
+    return Arrays.binarySearch(propertyNames, propertyName);
+  }
+
+
+  public EntryProperties newEntryProperties () throws NullPointerException
+  {
+    if (propertyNames == null)
+    {
+      throw new NullPointerException ("EntryProperties not initialized via EntryProperties.init()");
+    }
+    return new EntryProperties (this, propertyNames.length);
+  }
+  
+
+}
+