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/06/24 20:53:13 UTC
svn commit: r788120 [2/2] - in
/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper:
./ support/dictionaryResource/ support/dictionaryResource/annotatorAdaptor/
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=788120&r1=788119&r2=788120&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 Jun 24 18:53:12 2009
@@ -1,84 +1,82 @@
-/*
- * 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.IOException;
-import java.io.ObjectInputStream;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Properties;
-
-import org.apache.uima.analysis_engine.annotator.AnnotatorContext;
-import org.apache.uima.conceptMapper.Logger;
-import org.apache.uima.resource.DataResource;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.SharedResourceObject;
-/**
- * Implementation of a UIMA DictionaryResource
- */
-
-public class CompiledDictionaryResource_impl implements DictionaryResource, SharedResourceObject {
- /**
- * Hashtable of first words. Contains a DictEntries object keyed on word string for the first word
- * of every entry in the specified dictionary.
- */
- protected Hashtable<String, DictEntriesByLength> dictImpl;
-
- public DictionaryResource NewDictionaryResource(int initialSize) {
- throw new UnsupportedOperationException();
- }
-
- public DictEntriesByLength getEntries(String key) {
- return dictImpl.get(key);
- }
-
- public boolean isLoaded() {
- return true;
- }
-
- public Enumeration<String> keys() {
- return dictImpl.keys();
- }
-
- @SuppressWarnings("unchecked")
- public void load(DataResource data) throws ResourceInitializationException {
- try {
- ObjectInputStream ois = new ObjectInputStream(data.getInputStream());
- dictImpl = (Hashtable) ois.readObject();
- ois.close();
- } catch (IOException e) {
- throw new ResourceInitializationException(e);
- } catch (ClassNotFoundException e) {
- throw new ResourceInitializationException(e);
- }
- }
-
- public void loadDictionaryContents(AnnotatorContext context, Logger logger,
- String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
- String tokenizerDescriptor) throws ResourceInitializationException {
- // nothing to do
- }
-
- public void putEntry(String key, String entry, ArrayList<String> tokens, String unsortedEntry,
- int length, Properties props) {
- throw new UnsupportedOperationException();
- }
-
+/*
+ * 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.IOException;
+import java.io.ObjectInputStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.apache.uima.analysis_engine.annotator.AnnotatorContext;
+import org.apache.uima.conceptMapper.Logger;
+import org.apache.uima.resource.DataResource;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.SharedResourceObject;
+/**
+ * Implementation of a UIMA DictionaryResource
+ */
+
+public class CompiledDictionaryResource_impl implements DictionaryResource, SharedResourceObject {
+ /**
+ * Hashtable of first words. Contains a DictEntries object keyed on word string for the first word
+ * of every entry in the specified dictionary.
+ */
+ protected Hashtable<String, DictEntriesByLength> dictImpl;
+
+ public DictionaryResource NewDictionaryResource(int initialSize) {
+ throw new UnsupportedOperationException();
+ }
+
+ public DictEntriesByLength getEntries(String key) {
+ return dictImpl.get(key);
+ }
+
+ public boolean isLoaded() {
+ return true;
+ }
+
+ public Enumeration<String> keys() {
+ return dictImpl.keys();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void load(DataResource data) throws ResourceInitializationException {
+ try {
+ ObjectInputStream ois = new ObjectInputStream(data.getInputStream());
+ dictImpl = (Hashtable) ois.readObject();
+ ois.close();
+ } catch (IOException e) {
+ throw new ResourceInitializationException(e);
+ } catch (ClassNotFoundException e) {
+ throw new ResourceInitializationException(e);
+ }
+ }
+
+ public void loadDictionaryContents(AnnotatorContext context, Logger logger,
+ String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
+ String tokenizerDescriptor) throws ResourceInitializationException {
+ // nothing to do
+ }
+
+ public void putEntry(String key, String[] tokens, String unsortedEntry,
+ int length, EntryProperties props) {
+ throw new UnsupportedOperationException();
+ }
+
}
\ No newline at end of file
Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryLoaderException.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryLoaderException.java?rev=788120&r1=788119&r2=788120&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryLoaderException.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/DictionaryLoaderException.java Wed Jun 24 18:53:12 2009
@@ -1,36 +1,44 @@
-/*
- * 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;
-
-public class DictionaryLoaderException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = -8996670807380390034L;
-
- public DictionaryLoaderException() {
- super();
- }
-
- public DictionaryLoaderException(Throwable cause) {
- super(cause);
- }
-
-}
+/*
+ * 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;
+
+public class DictionaryLoaderException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8996670807380390034L;
+
+ public DictionaryLoaderException() {
+ super();
+ }
+
+ public DictionaryLoaderException(String message) {
+ super(message);
+ }
+
+ public DictionaryLoaderException(Throwable cause) {
+ super(cause);
+ }
+
+ public DictionaryLoaderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
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=788120&r1=788119&r2=788120&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 Jun 24 18:53:12 2009
@@ -1,138 +1,128 @@
-/*
- * 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.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import org.apache.uima.analysis_engine.annotator.AnnotatorContext;
-import org.apache.uima.conceptMapper.Logger;
-import org.apache.uima.resource.DataResource;
-import org.apache.uima.resource.ResourceInitializationException;
-
-/*
- * Interface for external UIMA dictionary resource
- */
-
-public interface DictionaryResource {
- // shared resource loader
- public void load(DataResource data) throws ResourceInitializationException;
-
- public DictionaryResource NewDictionaryResource(int initialSize);
-
- public interface DictEntriesByLength extends Serializable {
- public DictEntries getEntries(int length);
-
- void putEntry(int length, String entry, ArrayList<String> elements, String unsorted,
- Properties props);
-
- public Integer getLongest();
-
- public Integer getShortest();
- }
-
- public interface DictEntries extends Serializable {
-
- /**
- * @param elements
- * @param unsorted
- * @param key
- * @param length
- * @param props
- */
- void putEntry(String entry, Collection<String> elements, String unsorted, Properties props);
-
- /**
- * @param string
- * @return
- */
- ArrayList<DictEntry> getEntries();
-
- public String toString();
- }
-
- public interface DictEntry extends Serializable {
- public String getText();
-
- public void setElements(Collection<String> elements);
-
- public Collection<String> getElements();
-
- public void setText(String text);
-
- public String getUnsorted();
-
- public void setUnsorted(String text);
-
- public Properties getProperties();
-
- public void setProperties(Properties props);
-
- public String toString();
-
- }
-
- /**
- * return data structure containing a list of dictionary entries, sorted by number of tokens
- *
- * @param key
- * @return
- */
- public DictEntriesByLength getEntries(String key);
-
- /**
- * @param key
- * the key to index on
- * @param entry
- * String representation of tokens to be entered in the dictionary
- * @param tokens
- * array of tokens to be entered in the dictionary
- * @param unsortedEntry
- * String representation of tokens to be entered in the dictionary in sorted order, if
- * "entry" is sorted, otherwise null
- * @param length
- * Number of tokens in entry
- * @param props
- * the properties object for the dictionary entry
- */
- public void putEntry(String key, String entry, ArrayList<String> tokens, String unsortedEntry,
- int length, Properties props);
-
- /**
- * @return
- */
- public Enumeration<String> keys();
-
- public String toString();
-
- /**
- * @param context
- * @param tokenizerDescriptor
- * @param tokenAnnotationName
- * @throws ResourceInitializationException
- */
- public void loadDictionaryContents(AnnotatorContext context, Logger logger,
- String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
- String tokenizerDescriptor) throws ResourceInitializationException;
-
- public boolean isLoaded();
-}
+/*
+ * 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.ArrayList;
+import java.util.Enumeration;
+
+import org.apache.uima.analysis_engine.annotator.AnnotatorContext;
+import org.apache.uima.conceptMapper.Logger;
+import org.apache.uima.resource.DataResource;
+import org.apache.uima.resource.ResourceInitializationException;
+
+/*
+ * Interface for external UIMA dictionary resource
+ */
+
+public interface DictionaryResource {
+ // shared resource loader
+ public void load(DataResource data) throws ResourceInitializationException;
+
+ public DictionaryResource NewDictionaryResource(int initialSize);
+
+ public interface DictEntriesByLength extends Serializable {
+ public DictEntries getEntries(int length);
+
+ void putEntry(int length, String[] elements, String unsorted,
+ EntryProperties props);
+
+ public Integer getLongest();
+
+ public Integer getShortest();
+ }
+
+ public interface DictEntries extends Serializable {
+
+ /**
+ * @param elements
+ * @param unsorted
+ * @param props
+ */
+ void putEntry(String[] elements, String unsorted, EntryProperties props);
+
+ /**
+ * @param string
+ * @return
+ */
+ ArrayList<DictEntry> getEntries();
+
+ public String toString();
+ }
+
+ public interface DictEntry extends Serializable {
+ public void setElements(String[] elements);
+
+ public String[] getElements();
+
+ public String getUnsorted();
+
+ public void setUnsorted(String text);
+
+ public EntryProperties getProperties();
+
+ public void setProperties(EntryProperties props);
+
+ public String toString();
+
+ }
+
+ /**
+ * return data structure containing a list of dictionary entries, sorted by number of tokens
+ *
+ * @param key
+ * @return
+ */
+ public DictEntriesByLength getEntries(String key);
+
+ /**
+ * @param key
+ * the key to index on
+ * @param tokens
+ * array of tokens to be entered in the dictionary
+ * @param unsortedEntry
+ * String representation of tokens to be entered in the dictionary in sorted order, if
+ * "entry" is sorted, otherwise null
+ * @param length
+ * Number of tokens in entry
+ * @param props
+ * the properties object for the dictionary entry
+ */
+ public void putEntry(String key, String[] tokens, String unsortedEntry,
+ int length, EntryProperties props);
+
+ /**
+ * @return
+ */
+ public Enumeration<String> keys();
+
+ public String toString();
+
+ /**
+ * @param context
+ * @param tokenizerDescriptor
+ * @param tokenAnnotationName
+ * @throws ResourceInitializationException
+ */
+ public void loadDictionaryContents(AnnotatorContext context, Logger logger,
+ String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
+ String tokenizerDescriptor) throws ResourceInitializationException;
+
+ public boolean isLoaded();
+}
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=788120&r1=788119&r2=788120&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 Jun 24 18:53:12 2009
@@ -25,12 +25,10 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
-import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import java.util.regex.Pattern;
@@ -117,6 +115,12 @@
private static final String DEFAULT_LANGID = "en";
+ /** Configuration parameter key/label for the attribute list */
+ public static final String PARAM_ATTRIBUTE_LIST = "AttributeList";
+
+ public static final String PARAM_XML_PARSER = "XMLParserName";
+ private String XMLParserName = null;
+
public int entryNum = 0;
/**
@@ -160,15 +164,17 @@
*
* @param key
* the key to index on
- * @param phrase
- * the phrase to be entered in the dictionary
+ * @param elements
+ * the individual elements to be entered in the dictionary
+ * @param unsorted
+ * an unsorted string representation of the entry, if the contents of 'elements' has been sorted
* @param length
* the number of words in the phrase (>=1)
* @param props
- * the properties object for the dictionary entry
+ * the EntryProperties object for the dictionary entry
*/
- public void putEntry(String key, String text, ArrayList<String> elements, String unsorted,
- int length, Properties props) {
+ public void putEntry(String key, String[] elements, String unsorted,
+ int length, EntryProperties props) {
DictEntriesByLength entry = getEntries(key);
if (entry == null) {
@@ -181,7 +187,7 @@
// {
// System.err.println("ENTRY ELEMENT: " + elemIter.next ());
// }
- entry.putEntry(length, text, elements, unsorted, props);
+ entry.putEntry(length, elements, unsorted, props);
// System.err.println("ENTRY: '" + text + "', PROPS: ");
// Enumeration propKeys = props.keys();
// while (propKeys.hasMoreElements())
@@ -256,13 +262,17 @@
{
langID = DEFAULT_LANGID;
}
+
+ XMLParserName = (String) aContext.getConfigParameterValue(PARAM_XML_PARSER);
+
+ String [] entryPropertyNames = (String []) aContext.getConfigParameterValue(PARAM_ATTRIBUTE_LIST);
// 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);
+ tokenNormalizer, langID, entryPropertyNames);
logger.logInfo("...done");
// System.out.println ("done");
// System.err.println("NEW DICT:\n" + toString());
@@ -346,14 +356,14 @@
* @see org.apache.uima.conceptMapper.support.dictionaryResource.DictionaryResource.DictEntriesByLength#putEntry(int,
* java.lang.String, java.util.Properties)
*/
- public void putEntry(int length, String text, ArrayList<String> elements, String unsorted,
- Properties props) {
+ public void putEntry(int length, String[] elements, String unsorted,
+ EntryProperties props) {
DictEntries entry = getEntries(length);
if (entry == null) {
entry = new DictEntriesImpl();
entries.put(new Integer(length), entry);
}
- entry.putEntry(text, elements, unsorted, props);
+ entry.putEntry(elements, unsorted, props);
}
/*
@@ -407,13 +417,13 @@
/**
* Add a new phrase to an existing dictionary entry.
*
- * @param text
+ * @param elements
* the text to be entered in the dictionary
* @param props
* the properties object for the phrase
*/
- public void putEntry(String text, Collection<String> elements, String unsorted, Properties props) {
- add(new DictEntryImpl(text, elements, unsorted, props));
+ public void putEntry(String[] elements, String unsorted, EntryProperties props) {
+ add(new DictEntryImpl(elements, unsorted, props));
}
/*
@@ -439,13 +449,11 @@
public static class DictEntryImpl implements DictEntry {
private static final long serialVersionUID = -7723934333674544157L;
- String text;
-
- Collection<String> elements;
+ String[] elements;
String unsorted;
- Properties properties;
+ EntryProperties properties;
/**
* @param text
@@ -453,35 +461,19 @@
* @param unsorted
* @param properties
*/
- public DictEntryImpl(String text, Collection<String> elements, String unsorted,
- Properties properties) {
+ public DictEntryImpl(String[] elements, String unsorted,
+ EntryProperties properties) {
super();
this.properties = properties;
this.unsorted = unsorted;
- this.text = text;
this.elements = elements;
}
/**
- * @return Returns the text.
- */
- public String getText() {
- return text;
- }
-
- /**
- * @param text
- * The text to set.
- */
- public void setText(String text) {
- this.text = text;
- }
-
- /**
* @param properties
* The properties to set.
*/
- public void setProperties(Properties properties) {
+ public void setProperties(EntryProperties properties) {
this.properties = properties;
}
@@ -490,20 +482,19 @@
*
* @see org.apache.uima.conceptMapper.support.dictionaryResource.DictionaryResource.DictEntry#getProperties()
*/
- public Properties getProperties() {
+ public EntryProperties getProperties() {
return properties;
}
public String toString() {
- StringBuffer result = new StringBuffer("<DictEntry Text ='" + getText() + "'>");
- Enumeration<?> e = getProperties().propertyNames();
-
- while (e.hasMoreElements()) {
- String propName = (String) e.nextElement();
- result.append("<property name='" + propName + "'>");
- String item = getProperties().getProperty(propName);
- result.append(item);
- result.append("</property>\n");
+ StringBuffer result = new StringBuffer("<DictEntry Text ='" + getElements().toString() + "'>");
+
+ for (String propertyName : EntryPropertiesFactory.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();
@@ -528,11 +519,11 @@
this.unsorted = unsorted;
}
- public Collection<String> getElements() {
+ public String[] getElements() {
return elements;
}
- public void setElements(Collection<String> elements) {
+ public void setElements(String[] elements) {
this.elements = elements;
}
@@ -570,7 +561,7 @@
*/
private class DictLoader extends DefaultHandler {
/** Default parser name. */
- protected static final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
+ //protected static final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
/** Default name of element that contains dictionary records. */
protected static final String DEFAULT_TOKEN_ELEM = "token";
@@ -612,7 +603,7 @@
private DictionaryResource dict;
/** Properties for current canonical form */
- private Properties props;
+ private EntryProperties props;
private AnnotatorAdaptor adaptor;
@@ -623,6 +614,8 @@
private TokenFilter tokenFilter;
private TokenNormalizer tokenNormalizer;
+
+ private EntryPropertiesFactory entryPropertiesFactory;
/**
* needed to access input stream, since cannot load external dict resource until TAE config
@@ -648,9 +641,13 @@
// create parser
try {
- parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME);
+ if (XMLParserName != null) {
+ parser = XMLReaderFactory.createXMLReader(XMLParserName);
+ } else {
+ parser = XMLReaderFactory.createXMLReader();
+ }
} catch (Exception e) {
- log.logError("Unable to instantiate dictionary parser (" + DEFAULT_PARSER_NAME + ")");
+ log.logError("Unable to instantiate dictionary parser (" + ((XMLParserName==null) ? "default XML parser" : XMLParserName) + ")");
throw (e);
}
parser.setContentHandler(this);
@@ -686,6 +683,16 @@
this.tokenNormalizer = tokenNormalizer;
}
+ protected void setPropertiesFactory (EntryPropertiesFactory factory)
+ {
+ this.entryPropertiesFactory = factory;
+ }
+
+ protected EntryPropertiesFactory getPropertiesFactory ()
+ {
+ return entryPropertiesFactory;
+ }
+
protected TokenNormalizer getTokenNormalizer() {
return tokenNormalizer;
}
@@ -719,11 +726,12 @@
if (raw.equals(token_elem)) { // starting new token entry
if (attrs != null) {
- props = new Properties();
- int attrCount = attrs.getLength();
- for (int i = 0; i < attrCount; i++) {
- props.setProperty(attrs.getQName(i), convertEntities(attrs.getValue(i)));
- }
+ props = getPropertiesFactory().newEntryProperties();
+ int attrCount = attrs.getLength();
+ for (int i = 0; i < attrCount; i++) {
+ props.setProperty(attrs.getQName(i), convertEntities(attrs.getValue(i)));
+ }
+
}
} else if (raw.equals(variant_elem)) { // variant for current token
if (attrs != null) {
@@ -732,7 +740,7 @@
// if this variant contains its own POS info, save token level POS info and set props to
// contain variant's
- Properties variantProperties = new Properties(props);
+ EntryProperties variantProperties = new EntryProperties(props);
// logger.logInfo("" + entryNum++);
//
// System.err.println("" + entryNum++);
@@ -799,7 +807,7 @@
//}
}
} else {
- variantProperties.setProperty(attrs.getQName(i), convertEntities(attrs.getValue(i)));
+ variantProperties.setProperty(attrs.getQName(i), convertEntities(attrs.getValue(i)));
}
}
@@ -813,7 +821,7 @@
Arrays.sort(elements);
}
- String tokenString = stringTogetherTokens(elements);
+ //String tokenString = stringTogetherTokens(elements);
//if (dumpDict)
//{
// System.err.println ("token string: " + tokenString);
@@ -823,7 +831,7 @@
// add to dictionary
if (sortElements) {
for (int i = 0; i < tokens.size(); i++) {
- dict.putEntry((String) tokens.get(i), tokenString, tokens, unsorted, tokens.size(),
+ dict.putEntry((String) tokens.get(i), elements, unsorted, elements.length,
variantProperties);
// System.err.println ("adding props for:" + tokenString);
// Enumeration propKeys = variantProperties.keys();
@@ -836,7 +844,7 @@
}
} else {
- dict.putEntry((String) tokens.get(0), tokenString, tokens, unsorted, tokens.size(),
+ dict.putEntry((String) tokens.get(0), elements, unsorted, elements.length,
variantProperties);
}
term_cnt++;
@@ -847,23 +855,8 @@
}
}
}
-
- /**
- * @param elements
- * @return
- */
- private String stringTogetherTokens(String[] elements) {
- StringBuffer tokenString = new StringBuffer();
-
- for (int i = 0; i < elements.length; i++) {
- if (i > 0) {
- tokenString.append(" ");
- }
- tokenString.append(elements[i]);
- }
- return tokenString.toString();
- }
-
+
+
//
// ErrorHandler methods
//
@@ -923,7 +916,7 @@
*/
public void setDictionary(InputStream dictStream, int initialDictEntries,
String tokenAnnotationName, String tokenTypeFeatureName, String tokenClassFeatureName,
- String tokenizerDescriptor, TokenFilter tokenFilter, TokenNormalizer tokenNormalizer, String langID)
+ String tokenizerDescriptor, TokenFilter tokenFilter, TokenNormalizer tokenNormalizer, String langID, String [] entryPropertyNames)
throws DictionaryLoaderException {
term_cnt = 0;
setTokenAnnotationName(tokenAnnotationName);
@@ -932,6 +925,8 @@
setTokenNormalizer(tokenNormalizer);
result = new Vector<DictionaryToken>();
+ setPropertiesFactory (EntryPropertiesFactory.create (entryPropertyNames));
+
getLogger().logInfo("Loading dictionary");
try {
adaptor = new AnnotatorAdaptor(getTokenizerDescriptor(), result, tokenAnnotationName,
@@ -972,6 +967,20 @@
return dictImpl.keys();
}
+
+ public static String stringTogetherTokens(String[] elements) {
+ StringBuffer tokenString = new StringBuffer();
+
+ for (int i = 0; i < elements.length; i++) {
+ if (i > 0) {
+ tokenString.append(" ");
+ }
+ tokenString.append(elements[i]);
+ }
+ return tokenString.toString();
+ }
+
+
public String toString() {
StringBuffer result = new StringBuffer();
Added: 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=788120&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java (added)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryProperties.java Wed Jun 24 18:53:12 2009
@@ -0,0 +1,64 @@
+package org.apache.uima.conceptMapper.support.dictionaryResource;
+
+import java.io.Serializable;
+
+public class EntryProperties implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private String [] properties;
+
+ /**
+ *
+ * @param factory
+ * @param maxNumberOfProperties
+ * @throws NullPointerException
+ *
+ * should only be called by factory
+ */
+ public EntryProperties (EntryPropertiesFactory factory, int maxNumberOfProperties) throws NullPointerException
+ {
+ if (factory == null)
+ {
+ throw new NullPointerException ("EntryProperties not initialized via EntryProperties.init()");
+ }
+ properties = new String [maxNumberOfProperties];
+ }
+
+ public EntryProperties (EntryProperties toCopyFrom)
+ {
+ properties = toCopyFrom.properties.clone();
+ }
+
+
+ public String getProperty(String propertyName) {
+ return getProperty(propertyName, null);
+ }
+
+ public String getProperty(String propertyName, String defaultValue) {
+ int propertyID = EntryPropertiesFactory.getPropertyID (propertyName);
+ if (propertyID < 0)
+ {
+ return defaultValue;
+ }
+ else
+ {
+ return properties[propertyID];
+ }
+ }
+
+ public void setProperty(String propertyName, String propertyValue) {
+ int propertyID = EntryPropertiesFactory.getPropertyID (propertyName);
+ if (propertyID < 0)
+ {
+ // do nothing
+ }
+ else
+ {
+ properties[propertyID] = propertyValue;
+ }
+ }
+
+}
Added: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesFactory.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesFactory.java?rev=788120&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesFactory.java (added)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/EntryPropertiesFactory.java Wed Jun 24 18:53:12 2009
@@ -0,0 +1,45 @@
+package org.apache.uima.conceptMapper.support.dictionaryResource;
+
+import java.util.Arrays;
+
+public class EntryPropertiesFactory {
+
+ private static String [] propertyNames = null;
+
+ public static EntryPropertiesFactory create (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);
+ }
+ return new EntryPropertiesFactory ();
+ }
+
+ public static String [] propertyNames ()
+ {
+ return propertyNames;
+ }
+
+ public static 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);
+ }
+
+
+}
Modified: incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/annotatorAdaptor/AnnotatorAdaptor.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/annotatorAdaptor/AnnotatorAdaptor.java?rev=788120&r1=788119&r2=788120&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/annotatorAdaptor/AnnotatorAdaptor.java (original)
+++ incubator/uima/sandbox/trunk/ConceptMapper/src/main/java/org/apache/uima/conceptMapper/support/dictionaryResource/annotatorAdaptor/AnnotatorAdaptor.java Wed Jun 24 18:53:12 2009
@@ -19,6 +19,7 @@
package org.apache.uima.conceptMapper.support.dictionaryResource.annotatorAdaptor;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.Vector;
import org.apache.uima.UIMAFramework;
@@ -36,6 +37,7 @@
import org.apache.uima.conceptMapper.support.tokens.TokenFilter;
import org.apache.uima.conceptMapper.support.tokens.UnknownTypeException;
import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
@@ -87,10 +89,17 @@
public void initCPM() throws DictionaryLoaderException {
try {
+ ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
+ String dp = System.getProperty("uima.datapath");
+ if (null != dp) {
+ resMgr.setDataPath(dp);
+ }
ae = UIMAFramework.produceAnalysisEngine(aeSpecifier);
cas = ae.newCAS();
} catch (ResourceInitializationException e) {
throw new DictionaryLoaderException(e);
+ } catch (MalformedURLException e) {
+ throw new DictionaryLoaderException(e);
}
}