Revision: 15106
http://gate.svn.sourceforge.net/gate/?rev=15106&view=rev
Author: nirajaswani
Date: 2012-01-18 13:42:55 +0000 (Wed, 18 Jan 2012)
Log Message:
-----------
added a fucntionality to specify annotation type in the list definition file
which is used later by the default gazetteer to annotation all entries from the
list with the specified annotation type. Partial code was provided from ECW
Modified Paths:
--------------
gate/trunk/src/gate/creole/gazetteer/DefaultGazetteer.java
gate/trunk/src/gate/creole/gazetteer/LinearNode.java
gate/trunk/src/gate/creole/gazetteer/Lookup.java
gate/trunk/src/gate/gui/GazetteerEditor.java
Modified: gate/trunk/src/gate/creole/gazetteer/DefaultGazetteer.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/DefaultGazetteer.java 2012-01-18
07:30:11 UTC (rev 15105)
+++ gate/trunk/src/gate/creole/gazetteer/DefaultGazetteer.java 2012-01-18
13:42:55 UTC (rev 15106)
@@ -141,7 +141,7 @@
*/
protected void readList(LinearNode node, boolean add)
throws ResourceInstantiationException{
- String listName, majorType, minorType, languages;
+ String listName, majorType, minorType, languages,annotationType;
if ( null == node ) {
throw new ResourceInstantiationException(" LinearNode node is null ");
}
@@ -150,6 +150,7 @@
majorType = node.getMajorType();
minorType = node.getMinorType();
languages = node.getLanguage();
+ annotationType = node.getAnnotationType();
GazetteerList gazList = (GazetteerList)listsByNode.get(node);
if (null == gazList) {
throw new ResourceInstantiationException("gazetteer list not found by
node");
@@ -158,7 +159,7 @@
Iterator iline = gazList.iterator();
// create default lookup for entries with no arbitrary features
- Lookup defaultLookup = new Lookup(listName,majorType, minorType,
languages);
+ Lookup defaultLookup = new Lookup(listName,majorType, minorType,
languages,annotationType);
defaultLookup.list = node.getList();
if ( null != mappingDefinition){
MappingNode mnode = mappingDefinition.getNodeByList(defaultLookup.list);
@@ -179,7 +180,7 @@
lookup = defaultLookup;
} else {
// create a new Lookup object with features
- lookup = new Lookup(listName, majorType, minorType, languages);
+ lookup = new Lookup(listName, majorType, minorType,
languages,annotationType);
lookup.list = node.getList();
if(null != mappingDefinition) {
MappingNode mnode = mappingDefinition.getNodeByList(lookup.list);
@@ -430,10 +431,17 @@
fm.putAll(currentLookup.features);
}
try{
- annotationSet.add(new Long(matchedRegionStart),
- new Long(matchedRegionEnd + 1),
- LOOKUP_ANNOTATION_TYPE,
- fm);
+// if(currentLookup.annotationType==null ||
"".equals(currentLookup.annotationType)){
+// annotationSet.add(new Long(matchedRegionStart),
+// new Long(matchedRegionEnd + 1),
+// LOOKUP_ANNOTATION_TYPE,
+// fm);
+// }else{
+ annotationSet.add(new Long(matchedRegionStart),
+ new Long(matchedRegionEnd + 1),
+ currentLookup.annotationType, //this pojo attribute
will have Lookup as a default tag.
+ fm);
+ // }
} catch(InvalidOffsetException ioe) {
throw new GateRuntimeException(ioe.toString());
}
Modified: gate/trunk/src/gate/creole/gazetteer/LinearNode.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/LinearNode.java 2012-01-18
07:30:11 UTC (rev 15105)
+++ gate/trunk/src/gate/creole/gazetteer/LinearNode.java 2012-01-18
13:42:55 UTC (rev 15106)
@@ -1,64 +1,98 @@
/*
* LinearNode.java
- *
+ *
* Copyright (c) 2002, The University of Sheffield.
- *
- * This file is part of GATE (see http://gate.ac.uk/), and is free
- * software, licenced under the GNU Library General Public License,
- * Version 2, June1991.
- *
+ *
+ * This file is part of GATE (see http://gate.ac.uk/), and is free software,
+ * licenced under the GNU Library General Public License, Version 2, June1991.
+ *
* A copy of this licence is included in the distribution in the file
* licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
- *
+ *
* borislav popov 02/2002
- *
*/
package gate.creole.gazetteer;
+import gate.creole.ANNIEConstants;
-
-/**Linear node specifies an entry of the type :
- * list:major:minor:language */
+/**
+ * Linear node specifies an entry of the type :
list:major:minor:language:annotationType
+ */
public class LinearNode {
-
/** the gazetteer list from the node */
private String list;
+
/** the minor type from the node */
private String minor;
+
/** the major type from the node */
private String major;
+
/** the languages member from the node */
private String language;
+ /** the annotationType member from the node **/
+ private String annotationType;
+
/**
+ * Constructor
+ *
+ * @param list
+ * name of the list
+ * @param minor
+ * minor type
+ * @param major
+ * major type
+ * @param language
+ * language feature
+ * @param annotationType
+ * the annotation type that should be used for annotating mentions
of
+ * entries from the list
+ */
+ public LinearNode(String list, String minor, String major, String language,
+ String annotationType) {
+ this.list = list;
+ this.minor = minor;
+ this.major = major;
+ this.language = language;
+ this.annotationType = annotationType;
+ }
+
+ /**
* Constructs a linear node given its elements
- * @param aList the gazetteer list file name
- * @param aMajor the major type
- * @param aMinor the minor type
- * @param aLanguage the language(s)
+ *
+ * @param aList
+ * the gazetteer list file name
+ * @param aMajor
+ * the major type
+ * @param aMinor
+ * the minor type
+ * @param aLanguage
+ * the language(s)
*/
- public LinearNode(String aList,String aMajor,String aMinor, String
aLanguage) {
- list = aList;
- minor = aMinor;
- major = aMajor;
- language = aLanguage;
+ public LinearNode(String aList, String aMajor, String aMinor, String
aLanguage) {
+ this(aLanguage, aMajor, aMinor, aLanguage, null);
} // LinearNode construct
/**
* Parses and create a linear node from a string
- * @param node the linear node to be parsed
+ *
+ * @param node
+ * the linear node to be parsed
* @throws InvalidFormatException
*/
- public LinearNode (String node) throws InvalidFormatException {
+ public LinearNode(String node) throws InvalidFormatException {
int firstColon = node.indexOf(':');
int secondColon = node.indexOf(':', firstColon + 1);
int thirdColon = node.indexOf(':', secondColon + 1);
- if(firstColon == -1){
- throw new InvalidFormatException("", "Line: " + node);
- }
+ int fourthColon = node.indexOf(':', thirdColon + 1);
+ annotationType = ANNIEConstants.LOOKUP_ANNOTATION_TYPE; // default value
+ // must be lookup
+ // for backword
+ // compatibility
+ if(firstColon == -1) { throw new InvalidFormatException("", "Line: " +
node); }
list = node.substring(0, firstColon);
-
- if(secondColon == -1){
+ if(secondColon == -1) {
major = node.substring(firstColon + 1);
minor = null;
language = null;
@@ -69,74 +103,128 @@
language = null;
} else {
minor = node.substring(secondColon + 1, thirdColon);
- language = node.substring(thirdColon + 1);
+ if(fourthColon == -1) {
+ language = node.substring(thirdColon + 1);
+ annotationType = ANNIEConstants.LOOKUP_ANNOTATION_TYPE;
+ } else {
+ language = node.substring(thirdColon + 1, fourthColon);
+ annotationType = node.substring(fourthColon + 1);
+ }
}
} // else
} // LinearNode concstruct
- /**Get the gazetteer list filename from the node
- * @return the gazetteer list filename */
+ /**
+ * Get the gazetteer list filename from the node
+ *
+ * @return the gazetteer list filename
+ */
public String getList() {
return list;
}
- /**Sets the gazetteer list filename for the node
- * @param aList the gazetteer list filename*/
+ /**
+ * Sets the gazetteer list filename for the node
+ *
+ * @param aList
+ * the gazetteer list filename
+ */
public void setList(String aList) {
list = aList;
}
- /** Gets the language of the node (the language is optional)
- * @return the language of the node */
+ /**
+ * Gets the language of the node (the language is optional)
+ *
+ * @return the language of the node
+ */
public String getLanguage() {
return language;
}
- /** Sets the language of the node
- * @param aLanguage the language of the node */
+ /**
+ * Sets the language of the node
+ *
+ * @param aLanguage
+ * the language of the node
+ */
public void setLanguage(String aLanguage) {
language = aLanguage;
}
- /** Gets the minor type
- * @return the minor type */
+ /**
+ * Gets the minor type
+ *
+ * @return the minor type
+ */
public String getMinorType() {
return minor;
}
- /** Sets the minor type
+ /**
+ * Sets the minor type
*/
public void setMinorType(String minorType) {
minor = minorType;
}
- /** Gets the major type
- * @return the major type*/
+ /**
+ * Gets the major type
+ *
+ * @return the major type
+ */
public String getMajorType() {
return major;
}
- /** Sets the major type
- * @param majorType the major type */
+ /**
+ * Sets the major type
+ *
+ * @param majorType
+ * the major type
+ */
public void setMajorType(String majorType) {
major = majorType;
}
/**
+ * Gets the annotationType
+ *
+ * @return the annotationType
+ */
+ public String getAnnotationType() {
+ return annotationType;
+ }
+
+ /**
+ * Sets the annotaionType
+ *
+ * @param annotationType
+ */
+ public void setAnnotationType(String annotationType) {
+ this.annotationType = annotationType;
+ }
+
+ /**
* Gets the string representation of this node
+ *
* @return the string representation of this node
*/
public String toString() {
- String result = list+':'+major;
-
- if ( (null!=minor) && (0 != minor.length()))
- result += ':'+minor;
-
- if ( (null!=language) && (0 != language.length())) {
- if ((null==minor) || (0 == minor.length()) )
- result +=':';
- result += ':'+language;
+ String result = list + ':' + major;
+ if((null != minor) && (0 != minor.length())) result += ':' + minor;
+ if((null != language) && (0 != language.length())) {
+ if((null == minor) || (0 == minor.length())) result += ':';
+ result += ':' + language;
}
+ // if the annotation type is Lookup we don't really need to add
+ // it to the definition file
+ if((null != annotationType) && (0 != annotationType.length())
+ && !annotationType.equals(ANNIEConstants.LOOKUP_ANNOTATION_TYPE)) {
+ if((null == minor) || (0 == minor.length())) result += ':';
+ if(language == null || (0 == language.length())) result += ':';
+ result += ':' + annotationType;
+ }
return result;
}
@@ -144,6 +232,9 @@
public int hashCode() {
final int prime = 31;
int result = 1;
+ result =
+ prime * result
+ + ((annotationType == null) ? 0 : annotationType.hashCode());
result = prime * result + ((language == null) ? 0 : language.hashCode());
result = prime * result + ((list == null) ? 0 : list.hashCode());
result = prime * result + ((major == null) ? 0 : major.hashCode());
@@ -157,6 +248,9 @@
if(obj == null) return false;
if(getClass() != obj.getClass()) return false;
LinearNode other = (LinearNode)obj;
+ if(annotationType == null) {
+ if(other.annotationType != null) return false;
+ } else if(!annotationType.equals(other.annotationType)) return false;
if(language == null) {
if(other.language != null) return false;
} else if(!language.equals(other.language)) return false;
@@ -171,5 +265,4 @@
} else if(!minor.equals(other.minor)) return false;
return true;
}
-
} // class LinearNode
\ No newline at end of file
Modified: gate/trunk/src/gate/creole/gazetteer/Lookup.java
===================================================================
--- gate/trunk/src/gate/creole/gazetteer/Lookup.java 2012-01-18 07:30:11 UTC
(rev 15105)
+++ gate/trunk/src/gate/creole/gazetteer/Lookup.java 2012-01-18 13:42:55 UTC
(rev 15106)
@@ -17,6 +17,7 @@
package gate.creole.gazetteer;
+import gate.creole.ANNIEConstants;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -49,13 +50,26 @@
* @param major major type
* @param minor minor type
* @param theLanguages the languages
+ * @param annotationType
*/
- public Lookup(String theList, String major, String minor, String
theLanguages){
+ public Lookup(String theList, String major, String minor, String
theLanguages,String annType){
majorType = major;
minorType = minor;
languages = theLanguages;
list = theList;
+ annotationType = annType;
}
+ /**
+ * Creates a new Lookup value with the given major and minor types and
+ * languages.
+ *
+ * @param major major type
+ * @param minor minor type
+ * @param theLanguages the languages
+ */
+ public Lookup(String theList, String major, String minor, String
theLanguages){
+
this(theList,major,minor,theLanguages,ANNIEConstants.LOOKUP_ANNOTATION_TYPE);
+ }
/** Tha major type for this lookup, e.g. "Organisation" */
public String majorType;
@@ -75,6 +89,9 @@
/** the list represented by this lookup*/
public String list;
+
+ /** annotation type that should be used to create a lookup*/
+ public String annotationType;
/**Returns a string representation of this lookup in the format
* This method is used in equals()
Modified: gate/trunk/src/gate/gui/GazetteerEditor.java
===================================================================
--- gate/trunk/src/gate/gui/GazetteerEditor.java 2012-01-18 07:30:11 UTC
(rev 15105)
+++ gate/trunk/src/gate/gui/GazetteerEditor.java 2012-01-18 13:42:55 UTC
(rev 15106)
@@ -55,7 +55,7 @@
* Editor for {@link gate.creole.gazetteer.Gazetteer ANNIE Gazetteer}.
<pre>
Main features:
-- left table with 4 columns (List name, Major, Minor, Language) for the
+- left table with 5 columns (List name, Major, Minor, Language,
AnnotationType) for the
definition
- right table with 1+n columns (Value, Feature 1...Feature n) for the lists
- 'Save' on the context menu of the resources tree and tab
@@ -79,6 +79,7 @@
definitionTableModel.addColumn("Major");
definitionTableModel.addColumn("Minor");
definitionTableModel.addColumn("Language");
+ definitionTableModel.addColumn("Annotation type");
listTableModel = new ListTableModel();
actions = new ArrayList<Action>();
actions.add(new SaveAndReinitialiseGazetteerAction());
@@ -476,6 +477,7 @@
// update linear nodes with changes in the definition table
definitionTableModel.addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
+ if(selectedLinearNode == null) return;
int r = e.getFirstRow();
switch (e.getType()) {
case TableModelEvent.UPDATE:
@@ -522,11 +524,16 @@
if (oldValue != null && oldValue.equals(newValue)) { return; }
selectedLinearNode.setMinorType(newValue);
linearDefinition.setModified(true);
- } else {
+ } else if (c == 3){
String oldValue = selectedLinearNode.getLanguage();
if (oldValue != null && oldValue.equals(newValue)) { return; }
selectedLinearNode.setLanguage(newValue);
linearDefinition.setModified(true);
+ } else {
+ String oldValue = selectedLinearNode.getAnnotationType();
+ if (oldValue != null && oldValue.equals(newValue)) { return; }
+ selectedLinearNode.setAnnotationType(newValue);
+ linearDefinition.setModified(true);
}
break;
}
@@ -667,6 +674,7 @@
values.add(node.getMajorType() == null ? "" : node.getMajorType());
values.add(node.getMinorType() == null ? "" : node.getMinorType());
values.add(node.getLanguage() == null ? "" : node.getLanguage());
+ values.add(node.getAnnotationType() == null ? "" :
node.getAnnotationType());
definitionTableModel.addRow(values.toArray());
values.clear();
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs