You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/01/11 00:12:37 UTC
svn commit: r1431721 [3/19] - in /uima/sandbox/uimafit/trunk:
uimafit-examples/src/main/java/org/apache/uima/fit/examples/experiment/pos/
uimafit-examples/src/main/java/org/apache/uima/fit/examples/getstarted/
uimafit-examples/src/main/java/org/apache/...
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting.java Thu Jan 10 23:12:33 2013
@@ -1,4 +1,3 @@
-
/* First created by JCasGen Fri Apr 02 09:55:38 MDT 2010 */
package org.apache.uima.fit.examples.tutorial.type;
@@ -7,70 +6,68 @@ import org.apache.uima.jcas.JCasRegistry
import org.apache.uima.jcas.cas.TOP_Type;
/**
- * Updated by JCasGen Fri Jun 11 20:10:52 MDT 2010 XML source:
- * C:/Users/Philip/Documents
- * /Academic/workspace/uimaFIT-examples/src/main/resources
- * /org/uimafit/examples/TypeSystem.xml
+ * Updated by JCasGen Fri Jun 11 20:10:52 MDT 2010 XML source: C:/Users/Philip/Documents
+ * /Academic/workspace/uimaFIT-examples/src/main/resources /org/uimafit/examples/TypeSystem.xml
*
* @generated
*/
public class UimaMeeting extends Meeting {
- /**
- * @generated
- * @ordered
- */
- public final static int typeIndexID = JCasRegistry.register(UimaMeeting.class);
-
- /**
- * @generated
- * @ordered
- */
- public final static int type = typeIndexID;
-
- /** @generated */
- public int getTypeIndexID() {
- return typeIndexID;
- }
-
- /**
- * Never called. Disable default constructor
- *
- * @generated
- */
- protected UimaMeeting() {
- }
-
- /**
- * Internal - constructor used by generator
- *
- * @generated
- */
- public UimaMeeting(int addr, TOP_Type type) {
- super(addr, type);
- readObject();
- }
-
- /** @generated */
- public UimaMeeting(JCas jcas) {
- super(jcas);
- readObject();
- }
-
- /** @generated */
- public UimaMeeting(JCas jcas, int begin, int end) {
- super(jcas);
- setBegin(begin);
- setEnd(end);
- readObject();
- }
-
- /**
- * <!-- begin-user-doc --> Write your own initialization here <!--
- * end-user-doc -->
- *
- * @generated modifiable
- */
- private void readObject() {
- }
+ /**
+ * @generated
+ * @ordered
+ */
+ public final static int typeIndexID = JCasRegistry.register(UimaMeeting.class);
+
+ /**
+ * @generated
+ * @ordered
+ */
+ public final static int type = typeIndexID;
+
+ /** @generated */
+ @Override
+ public int getTypeIndexID() {
+ return typeIndexID;
+ }
+
+ /**
+ * Never called. Disable default constructor
+ *
+ * @generated
+ */
+ protected UimaMeeting() {
+ }
+
+ /**
+ * Internal - constructor used by generator
+ *
+ * @generated
+ */
+ public UimaMeeting(int addr, TOP_Type type) {
+ super(addr, type);
+ readObject();
+ }
+
+ /** @generated */
+ public UimaMeeting(JCas jcas) {
+ super(jcas);
+ readObject();
+ }
+
+ /** @generated */
+ public UimaMeeting(JCas jcas, int begin, int end) {
+ super(jcas);
+ setBegin(begin);
+ setEnd(end);
+ readObject();
+ }
+
+ /**
+ * <!-- begin-user-doc --> Write your own initialization here <!-- end-user-doc -->
+ *
+ * @generated modifiable
+ */
+ private void readObject() {
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting_Type.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting_Type.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting_Type.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/tutorial/type/UimaMeeting_Type.java Thu Jan 10 23:12:33 2013
@@ -1,13 +1,13 @@
/* First created by JCasGen Fri Apr 02 09:55:38 MDT 2010 */
package org.apache.uima.fit.examples.tutorial.type;
-import org.apache.uima.jcas.JCas;
-import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.cas.impl.FSGenerator;
-import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.impl.TypeImpl;
-import org.apache.uima.cas.Type;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
/**
* Updated by JCasGen Fri Jun 11 20:10:52 MDT 2010
@@ -15,45 +15,48 @@ import org.apache.uima.cas.Type;
* @generated
*/
public class UimaMeeting_Type extends Meeting_Type {
- /** @generated */
- protected FSGenerator getFSGenerator() {
- return fsGenerator;
- }
-
- /** @generated */
- private final FSGenerator fsGenerator = new FSGenerator() {
- public FeatureStructure createFS(int addr, CASImpl cas) {
- if (UimaMeeting_Type.this.useExistingInstance) {
- // Return eq fs instance if already created
- FeatureStructure fs = UimaMeeting_Type.this.jcas.getJfsFromCaddr(addr);
- if (null == fs) {
- fs = new UimaMeeting(addr, UimaMeeting_Type.this);
- UimaMeeting_Type.this.jcas.putJfsFromCaddr(addr, fs);
- return fs;
- }
- return fs;
- }
- else return new UimaMeeting(addr, UimaMeeting_Type.this);
- }
- };
-
- /** @generated */
- public final static int typeIndexID = UimaMeeting.typeIndexID;
-
- /**
- * @generated
- * @modifiable
- */
- public final static boolean featOkTst = JCasRegistry.getFeatOkTst("org.apache.uima.fit.examples.tutorial.type.UimaMeeting");
-
- /**
- * initialize variables to correspond with Cas Type and Features
- *
- * @generated
- */
- public UimaMeeting_Type(JCas jcas, Type casType) {
- super(jcas, casType);
- casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
+ /** @generated */
+ @Override
+ protected FSGenerator getFSGenerator() {
+ return fsGenerator;
+ }
+
+ /** @generated */
+ private final FSGenerator fsGenerator = new FSGenerator() {
+ public FeatureStructure createFS(int addr, CASImpl cas) {
+ if (UimaMeeting_Type.this.useExistingInstance) {
+ // Return eq fs instance if already created
+ FeatureStructure fs = UimaMeeting_Type.this.jcas.getJfsFromCaddr(addr);
+ if (null == fs) {
+ fs = new UimaMeeting(addr, UimaMeeting_Type.this);
+ UimaMeeting_Type.this.jcas.putJfsFromCaddr(addr, fs);
+ return fs;
+ }
+ return fs;
+ } else {
+ return new UimaMeeting(addr, UimaMeeting_Type.this);
+ }
+ }
+ };
+
+ /** @generated */
+ public final static int typeIndexID = UimaMeeting.typeIndexID;
+
+ /**
+ * @generated
+ * @modifiable
+ */
+ public final static boolean featOkTst = JCasRegistry
+ .getFeatOkTst("org.apache.uima.fit.examples.tutorial.type.UimaMeeting");
+
+ /**
+ * initialize variables to correspond with Cas Type and Features
+ *
+ * @generated
+ */
+ public UimaMeeting_Type(JCas jcas, Type casType) {
+ super(jcas, casType);
+ casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
- }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence.java Thu Jan 10 23:12:33 2013
@@ -1,78 +1,75 @@
-
/* First created by JCasGen Wed Jul 14 10:08:01 MDT 2010 */
package org.apache.uima.fit.examples.type;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;
-
import org.apache.uima.jcas.tcas.Annotation;
/**
- * Updated by JCasGen Wed Jul 14 10:08:01 MDT 2010 XML source:
- * C:/Users/Philip/Documents
+ * Updated by JCasGen Wed Jul 14 10:08:01 MDT 2010 XML source: C:/Users/Philip/Documents
* /Academic/workspace/uimafit-parent/uimaFIT-examples/src
* /main/resources/org/uimafit/examples/TypeSystem.xml
*
* @generated
*/
public class Sentence extends Annotation {
- /**
- * @generated
- * @ordered
- */
- public final static int typeIndexID = JCasRegistry.register(Sentence.class);
-
- /**
- * @generated
- * @ordered
- */
- public final static int type = typeIndexID;
-
- /** @generated */
- public int getTypeIndexID() {
- return typeIndexID;
- }
-
- /**
- * Never called. Disable default constructor
- *
- * @generated
- */
- protected Sentence() {
- }
-
- /**
- * Internal - constructor used by generator
- *
- * @generated
- */
- public Sentence(int addr, TOP_Type type) {
- super(addr, type);
- readObject();
- }
-
- /** @generated */
- public Sentence(JCas jcas) {
- super(jcas);
- readObject();
- }
-
- /** @generated */
- public Sentence(JCas jcas, int begin, int end) {
- super(jcas);
- setBegin(begin);
- setEnd(end);
- readObject();
- }
-
- /**
- * <!-- begin-user-doc --> Write your own initialization here <!--
- * end-user-doc -->
- *
- * @generated modifiable
- */
- private void readObject() {
- }
+ /**
+ * @generated
+ * @ordered
+ */
+ public final static int typeIndexID = JCasRegistry.register(Sentence.class);
+
+ /**
+ * @generated
+ * @ordered
+ */
+ public final static int type = typeIndexID;
+
+ /** @generated */
+ @Override
+ public int getTypeIndexID() {
+ return typeIndexID;
+ }
+
+ /**
+ * Never called. Disable default constructor
+ *
+ * @generated
+ */
+ protected Sentence() {
+ }
+
+ /**
+ * Internal - constructor used by generator
+ *
+ * @generated
+ */
+ public Sentence(int addr, TOP_Type type) {
+ super(addr, type);
+ readObject();
+ }
+
+ /** @generated */
+ public Sentence(JCas jcas) {
+ super(jcas);
+ readObject();
+ }
+
+ /** @generated */
+ public Sentence(JCas jcas, int begin, int end) {
+ super(jcas);
+ setBegin(begin);
+ setEnd(end);
+ readObject();
+ }
+
+ /**
+ * <!-- begin-user-doc --> Write your own initialization here <!-- end-user-doc -->
+ *
+ * @generated modifiable
+ */
+ private void readObject() {
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence_Type.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence_Type.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence_Type.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Sentence_Type.java Thu Jan 10 23:12:33 2013
@@ -1,13 +1,13 @@
/* First created by JCasGen Wed Jul 14 10:08:01 MDT 2010 */
package org.apache.uima.fit.examples.type;
-import org.apache.uima.jcas.JCas;
-import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.cas.impl.FSGenerator;
-import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.impl.TypeImpl;
-import org.apache.uima.cas.Type;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.tcas.Annotation_Type;
/**
@@ -16,46 +16,48 @@ import org.apache.uima.jcas.tcas.Annotat
* @generated
*/
public class Sentence_Type extends Annotation_Type {
- /** @generated */
- @Override
- protected FSGenerator getFSGenerator() {
- return fsGenerator;
- }
-
- /** @generated */
- private final FSGenerator fsGenerator = new FSGenerator() {
- public FeatureStructure createFS(int addr, CASImpl cas) {
- if (Sentence_Type.this.useExistingInstance) {
- // Return eq fs instance if already created
- FeatureStructure fs = Sentence_Type.this.jcas.getJfsFromCaddr(addr);
- if (null == fs) {
- fs = new Sentence(addr, Sentence_Type.this);
- Sentence_Type.this.jcas.putJfsFromCaddr(addr, fs);
- return fs;
- }
- return fs;
- }
- else return new Sentence(addr, Sentence_Type.this);
- }
- };
-
- /** @generated */
- public final static int typeIndexID = Sentence.typeIndexID;
-
- /**
- * @generated
- * @modifiable
- */
- public final static boolean featOkTst = JCasRegistry.getFeatOkTst("org.apache.uima.fit.examples.type.Sentence");
-
- /**
- * initialize variables to correspond with Cas Type and Features
- *
- * @generated
- */
- public Sentence_Type(JCas jcas, Type casType) {
- super(jcas, casType);
- casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
+ /** @generated */
+ @Override
+ protected FSGenerator getFSGenerator() {
+ return fsGenerator;
+ }
+
+ /** @generated */
+ private final FSGenerator fsGenerator = new FSGenerator() {
+ public FeatureStructure createFS(int addr, CASImpl cas) {
+ if (Sentence_Type.this.useExistingInstance) {
+ // Return eq fs instance if already created
+ FeatureStructure fs = Sentence_Type.this.jcas.getJfsFromCaddr(addr);
+ if (null == fs) {
+ fs = new Sentence(addr, Sentence_Type.this);
+ Sentence_Type.this.jcas.putJfsFromCaddr(addr, fs);
+ return fs;
+ }
+ return fs;
+ } else {
+ return new Sentence(addr, Sentence_Type.this);
+ }
+ }
+ };
+
+ /** @generated */
+ public final static int typeIndexID = Sentence.typeIndexID;
+
+ /**
+ * @generated
+ * @modifiable
+ */
+ public final static boolean featOkTst = JCasRegistry
+ .getFeatOkTst("org.apache.uima.fit.examples.type.Sentence");
+
+ /**
+ * initialize variables to correspond with Cas Type and Features
+ *
+ * @generated
+ */
+ public Sentence_Type(JCas jcas, Type casType) {
+ super(jcas, casType);
+ casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
- }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token.java Thu Jan 10 23:12:33 2013
@@ -1,102 +1,101 @@
-
/* First created by JCasGen Wed Jul 14 10:08:01 MDT 2010 */
package org.apache.uima.fit.examples.type;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;
-
import org.apache.uima.jcas.tcas.Annotation;
/**
- * Updated by JCasGen Wed Jul 14 10:08:01 MDT 2010 XML source:
- * C:/Users/Philip/Documents
+ * Updated by JCasGen Wed Jul 14 10:08:01 MDT 2010 XML source: C:/Users/Philip/Documents
* /Academic/workspace/uimafit-parent/uimaFIT-examples/src
* /main/resources/org/uimafit/examples/TypeSystem.xml
*
* @generated
*/
public class Token extends Annotation {
- /**
- * @generated
- * @ordered
- */
- public final static int typeIndexID = JCasRegistry.register(Token.class);
-
- /**
- * @generated
- * @ordered
- */
- public final static int type = typeIndexID;
-
- /** @generated */
- public int getTypeIndexID() {
- return typeIndexID;
- }
-
- /**
- * Never called. Disable default constructor
- *
- * @generated
- */
- protected Token() {
- }
-
- /**
- * Internal - constructor used by generator
- *
- * @generated
- */
- public Token(int addr, TOP_Type type) {
- super(addr, type);
- readObject();
- }
-
- /** @generated */
- public Token(JCas jcas) {
- super(jcas);
- readObject();
- }
-
- /** @generated */
- public Token(JCas jcas, int begin, int end) {
- super(jcas);
- setBegin(begin);
- setEnd(end);
- readObject();
- }
-
- /**
- * <!-- begin-user-doc --> Write your own initialization here <!--
- * end-user-doc -->
- *
- * @generated modifiable
- */
- private void readObject() {
- }
-
- // *--------------*
- // * Feature: pos
-
- /**
- * getter for pos - gets
- *
- * @generated
- */
- public String getPos() {
- if (Token_Type.featOkTst && ((Token_Type) jcasType).casFeat_pos == null) jcasType.jcas.throwFeatMissing("pos",
- "org.apache.uima.fit.examples.type.Token");
- return jcasType.ll_cas.ll_getStringValue(addr, ((Token_Type) jcasType).casFeatCode_pos);
- }
-
- /**
- * setter for pos - sets
- *
- * @generated
- */
- public void setPos(String v) {
- if (Token_Type.featOkTst && ((Token_Type) jcasType).casFeat_pos == null) jcasType.jcas.throwFeatMissing("pos",
- "org.apache.uima.fit.examples.type.Token");
- jcasType.ll_cas.ll_setStringValue(addr, ((Token_Type) jcasType).casFeatCode_pos, v);
- }
+ /**
+ * @generated
+ * @ordered
+ */
+ public final static int typeIndexID = JCasRegistry.register(Token.class);
+
+ /**
+ * @generated
+ * @ordered
+ */
+ public final static int type = typeIndexID;
+
+ /** @generated */
+ @Override
+ public int getTypeIndexID() {
+ return typeIndexID;
+ }
+
+ /**
+ * Never called. Disable default constructor
+ *
+ * @generated
+ */
+ protected Token() {
+ }
+
+ /**
+ * Internal - constructor used by generator
+ *
+ * @generated
+ */
+ public Token(int addr, TOP_Type type) {
+ super(addr, type);
+ readObject();
+ }
+
+ /** @generated */
+ public Token(JCas jcas) {
+ super(jcas);
+ readObject();
+ }
+
+ /** @generated */
+ public Token(JCas jcas, int begin, int end) {
+ super(jcas);
+ setBegin(begin);
+ setEnd(end);
+ readObject();
+ }
+
+ /**
+ * <!-- begin-user-doc --> Write your own initialization here <!-- end-user-doc -->
+ *
+ * @generated modifiable
+ */
+ private void readObject() {
+ }
+
+ // *--------------*
+ // * Feature: pos
+
+ /**
+ * getter for pos - gets
+ *
+ * @generated
+ */
+ public String getPos() {
+ if (Token_Type.featOkTst && ((Token_Type) jcasType).casFeat_pos == null) {
+ jcasType.jcas.throwFeatMissing("pos", "org.apache.uima.fit.examples.type.Token");
+ }
+ return jcasType.ll_cas.ll_getStringValue(addr, ((Token_Type) jcasType).casFeatCode_pos);
+ }
+
+ /**
+ * setter for pos - sets
+ *
+ * @generated
+ */
+ public void setPos(String v) {
+ if (Token_Type.featOkTst && ((Token_Type) jcasType).casFeat_pos == null) {
+ jcasType.jcas.throwFeatMissing("pos", "org.apache.uima.fit.examples.type.Token");
+ }
+ jcasType.ll_cas.ll_setStringValue(addr, ((Token_Type) jcasType).casFeatCode_pos, v);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token_Type.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token_Type.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token_Type.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/main/java/org/apache/uima/fit/examples/type/Token_Type.java Thu Jan 10 23:12:33 2013
@@ -1,15 +1,15 @@
/* First created by JCasGen Wed Jul 14 10:08:01 MDT 2010 */
package org.apache.uima.fit.examples.type;
-import org.apache.uima.jcas.JCas;
-import org.apache.uima.jcas.JCasRegistry;
-import org.apache.uima.cas.impl.CASImpl;
-import org.apache.uima.cas.impl.FSGenerator;
+import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.cas.impl.TypeImpl;
import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.FSGenerator;
import org.apache.uima.cas.impl.FeatureImpl;
-import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.tcas.Annotation_Type;
/**
@@ -18,66 +18,74 @@ import org.apache.uima.jcas.tcas.Annotat
* @generated
*/
public class Token_Type extends Annotation_Type {
- /** @generated */
- protected FSGenerator getFSGenerator() {
- return fsGenerator;
- }
-
- /** @generated */
- private final FSGenerator fsGenerator = new FSGenerator() {
- public FeatureStructure createFS(int addr, CASImpl cas) {
- if (Token_Type.this.useExistingInstance) {
- // Return eq fs instance if already created
- FeatureStructure fs = Token_Type.this.jcas.getJfsFromCaddr(addr);
- if (null == fs) {
- fs = new Token(addr, Token_Type.this);
- Token_Type.this.jcas.putJfsFromCaddr(addr, fs);
- return fs;
- }
- return fs;
- }
- else return new Token(addr, Token_Type.this);
- }
- };
-
- /** @generated */
- public final static int typeIndexID = Token.typeIndexID;
-
- /**
- * @generated
- * @modifiable
- */
- public final static boolean featOkTst = JCasRegistry.getFeatOkTst("org.apache.uima.fit.examples.type.Token");
-
- /** @generated */
- final Feature casFeat_pos;
-
- /** @generated */
- final int casFeatCode_pos;
-
- /** @generated */
- public String getPos(int addr) {
- if (featOkTst && casFeat_pos == null) jcas.throwFeatMissing("pos", "org.apache.uima.fit.examples.type.Token");
- return ll_cas.ll_getStringValue(addr, casFeatCode_pos);
- }
-
- /** @generated */
- public void setPos(int addr, String v) {
- if (featOkTst && casFeat_pos == null) jcas.throwFeatMissing("pos", "org.apache.uima.fit.examples.type.Token");
- ll_cas.ll_setStringValue(addr, casFeatCode_pos, v);
- }
-
- /**
- * initialize variables to correspond with Cas Type and Features
- *
- * @generated
- */
- public Token_Type(JCas jcas, Type casType) {
- super(jcas, casType);
- casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
-
- casFeat_pos = jcas.getRequiredFeatureDE(casType, "pos", "uima.cas.String", featOkTst);
- casFeatCode_pos = (null == casFeat_pos) ? JCas.INVALID_FEATURE_CODE : ((FeatureImpl) casFeat_pos).getCode();
+ /** @generated */
+ @Override
+ protected FSGenerator getFSGenerator() {
+ return fsGenerator;
+ }
+
+ /** @generated */
+ private final FSGenerator fsGenerator = new FSGenerator() {
+ public FeatureStructure createFS(int addr, CASImpl cas) {
+ if (Token_Type.this.useExistingInstance) {
+ // Return eq fs instance if already created
+ FeatureStructure fs = Token_Type.this.jcas.getJfsFromCaddr(addr);
+ if (null == fs) {
+ fs = new Token(addr, Token_Type.this);
+ Token_Type.this.jcas.putJfsFromCaddr(addr, fs);
+ return fs;
+ }
+ return fs;
+ } else {
+ return new Token(addr, Token_Type.this);
+ }
+ }
+ };
+
+ /** @generated */
+ public final static int typeIndexID = Token.typeIndexID;
+
+ /**
+ * @generated
+ * @modifiable
+ */
+ public final static boolean featOkTst = JCasRegistry
+ .getFeatOkTst("org.apache.uima.fit.examples.type.Token");
+
+ /** @generated */
+ final Feature casFeat_pos;
+
+ /** @generated */
+ final int casFeatCode_pos;
+
+ /** @generated */
+ public String getPos(int addr) {
+ if (featOkTst && casFeat_pos == null) {
+ jcas.throwFeatMissing("pos", "org.apache.uima.fit.examples.type.Token");
+ }
+ return ll_cas.ll_getStringValue(addr, casFeatCode_pos);
+ }
+
+ /** @generated */
+ public void setPos(int addr, String v) {
+ if (featOkTst && casFeat_pos == null) {
+ jcas.throwFeatMissing("pos", "org.apache.uima.fit.examples.type.Token");
+ }
+ ll_cas.ll_setStringValue(addr, casFeatCode_pos, v);
+ }
+
+ /**
+ * initialize variables to correspond with Cas Type and Features
+ *
+ * @generated
+ */
+ public Token_Type(JCas jcas, Type casType) {
+ super(jcas, casType);
+ casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl) this.casType, getFSGenerator());
+
+ casFeat_pos = jcas.getRequiredFeatureDE(casType, "pos", "uima.cas.String", featOkTst);
+ casFeatCode_pos = (null == casFeat_pos) ? JCas.INVALID_FEATURE_CODE
+ : ((FeatureImpl) casFeat_pos).getCode();
- }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ExamplesTestBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ExamplesTestBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ExamplesTestBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ExamplesTestBase.java Thu Jan 10 23:12:33 2013
@@ -39,46 +39,45 @@ import org.junit.Before;
*
*/
public class ExamplesTestBase {
- private static ThreadLocal<JCas> JCAS = new ThreadLocal<JCas>();
+ private static ThreadLocal<JCas> JCAS = new ThreadLocal<JCas>();
- private static ThreadLocal<TypeSystemDescription> TYPE_SYSTEM_DESCRIPTION = new ThreadLocal<TypeSystemDescription>();
+ private static ThreadLocal<TypeSystemDescription> TYPE_SYSTEM_DESCRIPTION = new ThreadLocal<TypeSystemDescription>();
- private static ThreadLocal<TypePriorities> TYPE_PRIORITIES = new ThreadLocal<TypePriorities>();
+ private static ThreadLocal<TypePriorities> TYPE_PRIORITIES = new ThreadLocal<TypePriorities>();
- static {
- try {
- TypeSystemDescription tsd = createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
- TYPE_SYSTEM_DESCRIPTION.set(tsd);
-
- TypePriorities tp = createTypePriorities(DateAnnotation.class, DateTimeAnnotation.class, Meeting.class, RoomNumber.class,
- TimeAnnotation.class, UimaAcronym.class, UimaMeeting.class);
- TYPE_PRIORITIES.set(tp);
-
- JCas jCas = createJCas(tsd);
- JCAS.set(jCas);
- }
- catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- protected JCas jCas;
-
- protected TypeSystemDescription typeSystemDescription;
-
- protected TypePriorities typeSystemPriorities;
-
- /**
- * we do not want to create a new JCas object every time we run a test
- * because it is expensive (~100ms on my laptop). Instead, we will have one
- * JCas per thread sitting around that we will reset everytime a new test is
- * called.
- */
- @Before
- public void setUp() {
- jCas = JCAS.get();
- jCas.reset();
- typeSystemDescription = TYPE_SYSTEM_DESCRIPTION.get();
- typeSystemPriorities = TYPE_PRIORITIES.get();
- }
+ static {
+ try {
+ TypeSystemDescription tsd = createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
+ TYPE_SYSTEM_DESCRIPTION.set(tsd);
+
+ TypePriorities tp = createTypePriorities(DateAnnotation.class, DateTimeAnnotation.class,
+ Meeting.class, RoomNumber.class, TimeAnnotation.class, UimaAcronym.class,
+ UimaMeeting.class);
+ TYPE_PRIORITIES.set(tp);
+
+ JCas jCas = createJCas(tsd);
+ JCAS.set(jCas);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ protected JCas jCas;
+
+ protected TypeSystemDescription typeSystemDescription;
+
+ protected TypePriorities typeSystemPriorities;
+
+ /**
+ * we do not want to create a new JCas object every time we run a test because it is expensive
+ * (~100ms on my laptop). Instead, we will have one JCas per thread sitting around that we will
+ * reset everytime a new test is called.
+ */
+ @Before
+ public void setUp() {
+ jCas = JCAS.get();
+ jCas.reset();
+ typeSystemDescription = TYPE_SYSTEM_DESCRIPTION.get();
+ typeSystemPriorities = TYPE_PRIORITIES.get();
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator1Test.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator1Test.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator1Test.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator1Test.java Thu Jan 10 23:12:33 2013
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertNotNull;
import org.apache.uima.analysis_engine.AnalysisEngine;
-import org.apache.uima.fit.examples.tutorial.ex1.RoomNumberAnnotator;
import org.apache.uima.fit.examples.tutorial.type.RoomNumber;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
@@ -38,73 +37,73 @@ import org.junit.Test;
*/
public class RoomNumberAnnotator1Test {
- /**
- * This test instantiates the analysis engine using the descriptor file generated by
- * org.apache.uima.fit.tutorial.ex1.RoomNumberAnnotator.main(String[]).
- *
- * This test isn't so bad but requires an xml descriptor file for the analysis engine. While the
- * descriptor was automatically generated, you might not want your tests to rely on descriptor
- * files. This test also creates a new JCas object. Creating a new JCas is a bit expensive (>40
- * ms on my laptop) - so this can really add up over a large test suite.
- *
- * @throws Exception
- */
- @Test
- public void testRNA1() throws Exception {
- AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory
- .createAnalysisEngine("org.apache.uima.fit.examples.tutorial.ex1.RoomNumberAnnotator");
- JCas jCas = roomNumberAnnotatorAE.newJCas();
- jCas.setDocumentText("The meeting is over at Yorktown 01-144");
- roomNumberAnnotatorAE.process(jCas);
-
- RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
- assertNotNull(roomNumber);
- assertEquals("01-144", roomNumber.getCoveredText());
- assertEquals("Yorktown", roomNumber.getBuilding());
- }
-
- /**
- * This test is a bit better because we don't need a descriptor file for the analysis engine. We
- * still need a descriptor file for the type system but this isn't so bad as we expect there to
- * be a descriptor file for the type system as it is used to generate the Java jCas types. We
- * are still, unfortunately, creating a new JCas which is not so great.
- *
- * @throws Exception
- */
- @Test
- public void testRNA2() throws Exception {
- TypeSystemDescription typeSystemDescription = TypeSystemDescriptionFactory
- .createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
- AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory.createPrimitive(
- RoomNumberAnnotator.class, typeSystemDescription);
- JCas jCas = roomNumberAnnotatorAE.newJCas();
- jCas.setDocumentText("The meeting is over at Yorktown 01-144");
- roomNumberAnnotatorAE.process(jCas);
-
- RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
- assertNotNull(roomNumber);
- assertEquals("01-144", roomNumber.getCoveredText());
- assertEquals("Yorktown", roomNumber.getBuilding());
- }
-
- /**
- * This test requires no descriptor files for either the TypeSystemDescription or the
- * AnalysisEngine.
- *
- * @throws Exception
- */
- @Test
- public void testRNA3() throws Exception {
- AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory.createPrimitive(
- RoomNumberAnnotator.class);
- JCas jCas = roomNumberAnnotatorAE.newJCas();
- jCas.setDocumentText("The meeting is over at Yorktown 01-144");
- roomNumberAnnotatorAE.process(jCas);
-
- RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
- assertNotNull(roomNumber);
- assertEquals("01-144", roomNumber.getCoveredText());
- assertEquals("Yorktown", roomNumber.getBuilding());
- }
+ /**
+ * This test instantiates the analysis engine using the descriptor file generated by
+ * org.apache.uima.fit.tutorial.ex1.RoomNumberAnnotator.main(String[]).
+ *
+ * This test isn't so bad but requires an xml descriptor file for the analysis engine. While the
+ * descriptor was automatically generated, you might not want your tests to rely on descriptor
+ * files. This test also creates a new JCas object. Creating a new JCas is a bit expensive (>40 ms
+ * on my laptop) - so this can really add up over a large test suite.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRNA1() throws Exception {
+ AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory
+ .createAnalysisEngine("org.apache.uima.fit.examples.tutorial.ex1.RoomNumberAnnotator");
+ JCas jCas = roomNumberAnnotatorAE.newJCas();
+ jCas.setDocumentText("The meeting is over at Yorktown 01-144");
+ roomNumberAnnotatorAE.process(jCas);
+
+ RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
+ assertNotNull(roomNumber);
+ assertEquals("01-144", roomNumber.getCoveredText());
+ assertEquals("Yorktown", roomNumber.getBuilding());
+ }
+
+ /**
+ * This test is a bit better because we don't need a descriptor file for the analysis engine. We
+ * still need a descriptor file for the type system but this isn't so bad as we expect there to be
+ * a descriptor file for the type system as it is used to generate the Java jCas types. We are
+ * still, unfortunately, creating a new JCas which is not so great.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRNA2() throws Exception {
+ TypeSystemDescription typeSystemDescription = TypeSystemDescriptionFactory
+ .createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
+ AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory.createPrimitive(
+ RoomNumberAnnotator.class, typeSystemDescription);
+ JCas jCas = roomNumberAnnotatorAE.newJCas();
+ jCas.setDocumentText("The meeting is over at Yorktown 01-144");
+ roomNumberAnnotatorAE.process(jCas);
+
+ RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
+ assertNotNull(roomNumber);
+ assertEquals("01-144", roomNumber.getCoveredText());
+ assertEquals("Yorktown", roomNumber.getBuilding());
+ }
+
+ /**
+ * This test requires no descriptor files for either the TypeSystemDescription or the
+ * AnalysisEngine.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRNA3() throws Exception {
+ AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory
+ .createPrimitive(RoomNumberAnnotator.class);
+ JCas jCas = roomNumberAnnotatorAE.newJCas();
+ jCas.setDocumentText("The meeting is over at Yorktown 01-144");
+ roomNumberAnnotatorAE.process(jCas);
+
+ RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
+ assertNotNull(roomNumber);
+ assertEquals("01-144", roomNumber.getCoveredText());
+ assertEquals("Yorktown", roomNumber.getBuilding());
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator2Test.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator2Test.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator2Test.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/tutorial/ex1/RoomNumberAnnotator2Test.java Thu Jan 10 23:12:33 2013
@@ -23,37 +23,36 @@ import static org.junit.Assert.assertNot
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.fit.examples.tutorial.ExamplesTestBase;
-import org.apache.uima.fit.examples.tutorial.ex1.RoomNumberAnnotator;
import org.apache.uima.fit.examples.tutorial.type.RoomNumber;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.fit.util.JCasUtil;
import org.junit.Test;
/**
- * This class demonstrates some simple tests using uimaFIT using the
- * ExamplesTestBase. These tests have the advantage that a new JCas is not
- * created for each test.
+ * This class demonstrates some simple tests using uimaFIT using the ExamplesTestBase. These tests
+ * have the advantage that a new JCas is not created for each test.
*
*
*/
public class RoomNumberAnnotator2Test extends ExamplesTestBase {
- /**
- * This test is nice because the super classes provides the
- * typeSystemDescription and jCas objects.
- *
- * @throws Exception
- */
- @Test
- public void testRNA1() throws Exception {
- AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory.createPrimitive(RoomNumberAnnotator.class, typeSystemDescription);
- jCas.setDocumentText("The meeting is over at Yorktown 01-144");
- roomNumberAnnotatorAE.process(jCas);
+ /**
+ * This test is nice because the super classes provides the typeSystemDescription and jCas
+ * objects.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testRNA1() throws Exception {
+ AnalysisEngine roomNumberAnnotatorAE = AnalysisEngineFactory.createPrimitive(
+ RoomNumberAnnotator.class, typeSystemDescription);
+ jCas.setDocumentText("The meeting is over at Yorktown 01-144");
+ roomNumberAnnotatorAE.process(jCas);
- RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
- assertNotNull(roomNumber);
- assertEquals("01-144", roomNumber.getCoveredText());
- assertEquals("Yorktown", roomNumber.getBuilding());
- }
+ RoomNumber roomNumber = JCasUtil.selectByIndex(jCas, RoomNumber.class, 0);
+ assertNotNull(roomNumber);
+ assertEquals("01-144", roomNumber.getCoveredText());
+ assertEquals("Yorktown", roomNumber.getBuilding());
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/xmi/XmiTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/xmi/XmiTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/xmi/XmiTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-examples/src/test/java/org/apache/uima/fit/examples/xmi/XmiTest.java Thu Jan 10 23:12:33 2013
@@ -38,117 +38,120 @@ import org.apache.uima.resource.metadata
import org.junit.Test;
/**
- * This test demonstrates testing a "downstream" AnalysisEngine by means of an
- * XMI-serialized CAS. Here we have two "upstream" analysis engines, Annotator1
- * and Annotator2, which add annotations used by Annotator3.
+ * This test demonstrates testing a "downstream" AnalysisEngine by means of an XMI-serialized CAS.
+ * Here we have two "upstream" analysis engines, Annotator1 and Annotator2, which add annotations
+ * used by Annotator3.
*
*
*/
public class XmiTest extends ExamplesTestBase {
- /**
- * Here we are testing Annotator3 by setting up the "pipeline" and running
- * it before testing the final annotator.
- *
- * @throws Exception
- */
- @Test
- public void testWithoutXmi() throws Exception {
- AnalysisEngine a1 = AnalysisEngineFactory.createPrimitive(Annotator1.class, typeSystemDescription);
- AnalysisEngine a2 = AnalysisEngineFactory.createPrimitive(Annotator2.class, typeSystemDescription);
- AnalysisEngine a3 = AnalysisEngineFactory.createPrimitive(Annotator3.class, typeSystemDescription);
- jCas.setDocumentText("betgetjetletmetnetpetsetvetwetyet");
- SimplePipeline.runPipeline(jCas, a1, a2, a3);
-
- Sentence sentence = JCasUtil.selectByIndex(jCas, Sentence.class, 0);
- assertEquals("metnetpetsetvetwetyet", sentence.getCoveredText());
- }
-
- /**
- * In this test we have removed the dependency on running Annotator1 and
- * Annotator2 before running Annotator3 by introducing an XMI file that
- * contains the token annnotations created by Annotator1 and the pos tags
- * added by Annotator2. This is nice because both Annotator1 and Annotator2
- * do a pretty poor job at their tasks and you can imagine that in future
- * versions their behavior might change. However, Annotator3 does a
- * perfectly fine job doing what it does and tests for this analysis engine
- * should not have to change just because the behavior of Annotator1 and
- * Annotator2 will. Another option is to set up all the annotations required
- * by Annotator3 manually, but this approach can be tedious, time consuming,
- * error prone, and results in a lot of code.
- * <p>
- * The xmi file is generated once by running {@link #main(String[])}.
- * Hopefully, it will not be necessary to regenerate the xmi file often.
- *
- * @throws Exception
- */
- @Test
- public void testWithXmi() throws Exception {
- jCas = JCasFactory.createJCas("src/main/resources/org/apache/uima/fit/examples/xmi/1.xmi", typeSystemDescription);
- AnalysisEngine a3 = AnalysisEngineFactory.createPrimitive(Annotator3.class, typeSystemDescription);
- a3.process(jCas);
- Sentence sentence = JCasUtil.selectByIndex(jCas, Sentence.class, 0);
- assertEquals("metnetpetsetvetwetyet", sentence.getCoveredText());
- }
-
- /**
- * Here we generate an xmi file that will be used by {@link #testWithXmi()}.
- *
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- TypeSystemDescription tsd = createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
- AnalysisEngine a1 = AnalysisEngineFactory.createPrimitive(Annotator1.class, tsd);
- AnalysisEngine a2 = AnalysisEngineFactory.createPrimitive(Annotator2.class, tsd);
- AnalysisEngine xWriter = AnalysisEngineFactory.createPrimitive(XWriter.class, tsd, XWriter.PARAM_OUTPUT_DIRECTORY_NAME,
- "src/main/resources/org/apache/uima/fit/examples/xmi");
- JCas jCas = JCasFactory.createJCas(tsd);
- jCas.setDocumentText("betgetjetletmetnetpetsetvetwetyet");
- a1.process(jCas);
- a2.process(jCas);
- xWriter.process(jCas);
- xWriter.collectionProcessComplete();
- }
-
- /**
- * Creates a token for every three characters
- */
- public static class Annotator1 extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- String text = jCas.getDocumentText();
- for (int i = 0; i < text.length() - 3; i += 3) {
- new Token(jCas, i, i + 3).addToIndexes();
- }
- }
- }
-
- /**
- * sets the pos tag for each token to be the first letter of the token
- */
- public static class Annotator2 extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- for (Token token : select(jCas, Token.class)) {
- token.setPos(token.getCoveredText().substring(0, 1));
- }
- }
- }
-
- /**
- * creates a sentence from the begining of each token whose pos tag is "m"
- * to the end of the text.
- */
- public static class Annotator3 extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- for (Token token : select(jCas, Token.class)) {
- if (token.getPos().equals("m")) {
- new Sentence(jCas, token.getBegin(), jCas.getDocumentText().length()).addToIndexes();
- }
- }
- }
- }
+ /**
+ * Here we are testing Annotator3 by setting up the "pipeline" and running it before testing the
+ * final annotator.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testWithoutXmi() throws Exception {
+ AnalysisEngine a1 = AnalysisEngineFactory.createPrimitive(Annotator1.class,
+ typeSystemDescription);
+ AnalysisEngine a2 = AnalysisEngineFactory.createPrimitive(Annotator2.class,
+ typeSystemDescription);
+ AnalysisEngine a3 = AnalysisEngineFactory.createPrimitive(Annotator3.class,
+ typeSystemDescription);
+ jCas.setDocumentText("betgetjetletmetnetpetsetvetwetyet");
+ SimplePipeline.runPipeline(jCas, a1, a2, a3);
+
+ Sentence sentence = JCasUtil.selectByIndex(jCas, Sentence.class, 0);
+ assertEquals("metnetpetsetvetwetyet", sentence.getCoveredText());
+ }
+
+ /**
+ * In this test we have removed the dependency on running Annotator1 and Annotator2 before running
+ * Annotator3 by introducing an XMI file that contains the token annnotations created by
+ * Annotator1 and the pos tags added by Annotator2. This is nice because both Annotator1 and
+ * Annotator2 do a pretty poor job at their tasks and you can imagine that in future versions
+ * their behavior might change. However, Annotator3 does a perfectly fine job doing what it does
+ * and tests for this analysis engine should not have to change just because the behavior of
+ * Annotator1 and Annotator2 will. Another option is to set up all the annotations required by
+ * Annotator3 manually, but this approach can be tedious, time consuming, error prone, and results
+ * in a lot of code.
+ * <p>
+ * The xmi file is generated once by running {@link #main(String[])}. Hopefully, it will not be
+ * necessary to regenerate the xmi file often.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testWithXmi() throws Exception {
+ jCas = JCasFactory.createJCas("src/main/resources/org/apache/uima/fit/examples/xmi/1.xmi",
+ typeSystemDescription);
+ AnalysisEngine a3 = AnalysisEngineFactory.createPrimitive(Annotator3.class,
+ typeSystemDescription);
+ a3.process(jCas);
+ Sentence sentence = JCasUtil.selectByIndex(jCas, Sentence.class, 0);
+ assertEquals("metnetpetsetvetwetyet", sentence.getCoveredText());
+ }
+
+ /**
+ * Here we generate an xmi file that will be used by {@link #testWithXmi()}.
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ TypeSystemDescription tsd = createTypeSystemDescription("org.apache.uima.fit.examples.TypeSystem");
+ AnalysisEngine a1 = AnalysisEngineFactory.createPrimitive(Annotator1.class, tsd);
+ AnalysisEngine a2 = AnalysisEngineFactory.createPrimitive(Annotator2.class, tsd);
+ AnalysisEngine xWriter = AnalysisEngineFactory.createPrimitive(XWriter.class, tsd,
+ XWriter.PARAM_OUTPUT_DIRECTORY_NAME,
+ "src/main/resources/org/apache/uima/fit/examples/xmi");
+ JCas jCas = JCasFactory.createJCas(tsd);
+ jCas.setDocumentText("betgetjetletmetnetpetsetvetwetyet");
+ a1.process(jCas);
+ a2.process(jCas);
+ xWriter.process(jCas);
+ xWriter.collectionProcessComplete();
+ }
+
+ /**
+ * Creates a token for every three characters
+ */
+ public static class Annotator1 extends JCasAnnotator_ImplBase {
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ String text = jCas.getDocumentText();
+ for (int i = 0; i < text.length() - 3; i += 3) {
+ new Token(jCas, i, i + 3).addToIndexes();
+ }
+ }
+ }
+
+ /**
+ * sets the pos tag for each token to be the first letter of the token
+ */
+ public static class Annotator2 extends JCasAnnotator_ImplBase {
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ for (Token token : select(jCas, Token.class)) {
+ token.setPos(token.getCoveredText().substring(0, 1));
+ }
+ }
+ }
+
+ /**
+ * creates a sentence from the begining of each token whose pos tag is "m" to the end of the text.
+ */
+ public static class Annotator3 extends JCasAnnotator_ImplBase {
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ for (Token token : select(jCas, Token.class)) {
+ if (token.getPos().equals("m")) {
+ new Sentence(jCas, token.getBegin(), jCas.getDocumentText().length()).addToIndexes();
+ }
+ }
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-maven-plugin/src/main/java/org/apache/uima/fit/maven/GenerateDescriptorsMojo.java Thu Jan 10 23:12:33 2013
@@ -49,131 +49,113 @@ import org.xml.sax.SAXException;
*
* @see http://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html
*/
-@Mojo(name = "generate", defaultPhase = LifecyclePhase.PROCESS_CLASSES,
- requiresDependencyResolution = ResolutionScope.COMPILE,
- requiresDependencyCollection = ResolutionScope.COMPILE)
-public class GenerateDescriptorsMojo
- extends AbstractMojo
-{
- @Component
- private MavenProject project;
-
- private ClassLoader componentLoader;
-
- public void execute()
- throws MojoExecutionException
- {
- String[] files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
- new String[] { "class" });
-
- // Create a class loader which covers the classes compiled in the current project and all
- // dependencies.
- try {
- List<URL> urls = new ArrayList<URL>();
- for (Object object : project.getCompileClasspathElements()) {
- String path = (String) object;
- getLog().debug("Classpath entry: " + object);
- urls.add(new File(path).toURI().toURL());
- }
- for (Artifact dep : (Set<Artifact>) project.getDependencyArtifacts()) {
- getLog().debug("Classpath entry: " + dep.getFile());
- urls.add(dep.getFile().toURI().toURL());
- }
- componentLoader = new URLClassLoader(urls.toArray(new URL[] {}),
- getClass().getClassLoader());
- }
- catch (Exception e) {
- throw new MojoExecutionException("Cannot initialize classloader", e);
- }
-
- for (String file : files) {
- String base = file.substring(0, file.length() - 6);
- String clazzName = base.substring(project.getBuild().getOutputDirectory().length() + 1)
- .replace("/", ".");
- try {
- Class clazz = getClass(clazzName);
- ResourceSpecifier desc = null;
- switch (getType(clazz)) {
- case ANALYSIS_ENGINE:
- desc = AnalysisEngineFactory.createPrimitiveDescription(clazz);
- break;
- case COLLECTION_READER:
- desc = CollectionReaderFactory.createDescription(clazz);
- default:
- // Do nothing
- }
-
- if (desc != null) {
- toXML(desc, base + ".xml");
- }
- }
- catch (SAXException e) {
- getLog().warn("Cannot serialize descriptor for [" + clazzName + "]", e);
- }
- catch (IOException e) {
- getLog().warn("Cannot write descriptor for [" + clazzName + "]", e);
- }
- catch (ClassNotFoundException e) {
- getLog().warn("Cannot analyze class [" + clazzName + "]", e);
- }
- catch (ResourceInitializationException e) {
- getLog().warn("Cannot generate descriptor for [" + clazzName + "]", e);
- }
- }
- }
-
- /**
- * Save descriptor XML to file system.
- * @throws IOException
- * @throws SAXException
- */
- private void toXML(ResourceSpecifier aDesc, String aFilename) throws SAXException, IOException
- {
- OutputStream os = null;
- try {
- File out = new File(aFilename);
- getLog().info("Writing descriptor to: " + out);
- os = new FileOutputStream(out);
- aDesc.toXML(os);
- }
- finally {
- IOUtils.closeQuietly(os);
- }
- }
-
- /**
- * Load class using the component classloader.
- * @throws ClassNotFoundException
- */
- private Class getClass(String aClassName)
- throws ClassNotFoundException
- {
- return componentLoader.loadClass(aClassName);
- }
-
- /**
- * Determine what kind of class it is.
- * @throws ClassNotFoundException
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private ComponentType getType(Class aClass)
- throws ClassNotFoundException
- {
- Class iCR = getClass("org.apache.uima.collection.CollectionReader");
- Class iAE = getClass("org.apache.uima.analysis_component.AnalysisComponent");
- if (iCR.isAssignableFrom(aClass)) {
- return ComponentType.COLLECTION_READER;
- }
- else if (iAE.isAssignableFrom(aClass)) {
- return ComponentType.ANALYSIS_ENGINE;
- }
- else {
- return ComponentType.NONE;
- }
- }
-
- private enum ComponentType
- {
- COLLECTION_READER, ANALYSIS_ENGINE, NONE;
- }
+@Mojo(name = "generate", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE)
+public class GenerateDescriptorsMojo extends AbstractMojo {
+ @Component
+ private MavenProject project;
+
+ private ClassLoader componentLoader;
+
+ public void execute() throws MojoExecutionException {
+ String[] files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
+ new String[] { "class" });
+
+ // Create a class loader which covers the classes compiled in the current project and all
+ // dependencies.
+ try {
+ List<URL> urls = new ArrayList<URL>();
+ for (Object object : project.getCompileClasspathElements()) {
+ String path = (String) object;
+ getLog().debug("Classpath entry: " + object);
+ urls.add(new File(path).toURI().toURL());
+ }
+ for (Artifact dep : (Set<Artifact>) project.getDependencyArtifacts()) {
+ getLog().debug("Classpath entry: " + dep.getFile());
+ urls.add(dep.getFile().toURI().toURL());
+ }
+ componentLoader = new URLClassLoader(urls.toArray(new URL[] {}), getClass().getClassLoader());
+ } catch (Exception e) {
+ throw new MojoExecutionException("Cannot initialize classloader", e);
+ }
+
+ for (String file : files) {
+ String base = file.substring(0, file.length() - 6);
+ String clazzName = base.substring(project.getBuild().getOutputDirectory().length() + 1)
+ .replace("/", ".");
+ try {
+ Class clazz = getClass(clazzName);
+ ResourceSpecifier desc = null;
+ switch (getType(clazz)) {
+ case ANALYSIS_ENGINE:
+ desc = AnalysisEngineFactory.createPrimitiveDescription(clazz);
+ break;
+ case COLLECTION_READER:
+ desc = CollectionReaderFactory.createDescription(clazz);
+ default:
+ // Do nothing
+ }
+
+ if (desc != null) {
+ toXML(desc, base + ".xml");
+ }
+ } catch (SAXException e) {
+ getLog().warn("Cannot serialize descriptor for [" + clazzName + "]", e);
+ } catch (IOException e) {
+ getLog().warn("Cannot write descriptor for [" + clazzName + "]", e);
+ } catch (ClassNotFoundException e) {
+ getLog().warn("Cannot analyze class [" + clazzName + "]", e);
+ } catch (ResourceInitializationException e) {
+ getLog().warn("Cannot generate descriptor for [" + clazzName + "]", e);
+ }
+ }
+ }
+
+ /**
+ * Save descriptor XML to file system.
+ *
+ * @throws IOException
+ * @throws SAXException
+ */
+ private void toXML(ResourceSpecifier aDesc, String aFilename) throws SAXException, IOException {
+ OutputStream os = null;
+ try {
+ File out = new File(aFilename);
+ getLog().info("Writing descriptor to: " + out);
+ os = new FileOutputStream(out);
+ aDesc.toXML(os);
+ } finally {
+ IOUtils.closeQuietly(os);
+ }
+ }
+
+ /**
+ * Load class using the component classloader.
+ *
+ * @throws ClassNotFoundException
+ */
+ private Class getClass(String aClassName) throws ClassNotFoundException {
+ return componentLoader.loadClass(aClassName);
+ }
+
+ /**
+ * Determine what kind of class it is.
+ *
+ * @throws ClassNotFoundException
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private ComponentType getType(Class aClass) throws ClassNotFoundException {
+ Class iCR = getClass("org.apache.uima.collection.CollectionReader");
+ Class iAE = getClass("org.apache.uima.analysis_component.AnalysisComponent");
+ if (iCR.isAssignableFrom(aClass)) {
+ return ComponentType.COLLECTION_READER;
+ } else if (iAE.isAssignableFrom(aClass)) {
+ return ComponentType.ANALYSIS_ENGINE;
+ } else {
+ return ComponentType.NONE;
+ }
+ }
+
+ private enum ComponentType {
+ COLLECTION_READER, ANALYSIS_ENGINE, NONE;
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/SpringContextResourceManager.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/SpringContextResourceManager.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/SpringContextResourceManager.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/SpringContextResourceManager.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring;
import java.lang.reflect.Constructor;
@@ -39,134 +38,114 @@ import org.springframework.context.Appli
/**
* Allowing UIMA components to access beans from a {@link ApplicationContext context}.
- *
+ *
*/
-public class SpringContextResourceManager
- extends ResourceManager_impl
- implements ApplicationContextAware
-{
- private ApplicationContext context;
- private boolean autowireEnabled = false;
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public void initializeExternalResources(ResourceManagerConfiguration aConfiguration,
- String aQualifiedContextName, java.util.Map<String, Object> aAdditionalParams)
- throws ResourceInitializationException {
-
- for (String name : BeanFactoryUtils.beanNamesIncludingAncestors(context)) {
- Object registration = mInternalResourceRegistrationMap.get(name);
-
- if (registration == null) {
- try {
- // Register resource
- // ResourceRegistration unfortunately is package private
- Object reg = newInstance(
- "org.apache.uima.resource.impl.ResourceManager_impl$ResourceRegistration",
- Object.class, context.getBean(name),
- ExternalResourceDescription.class, null,
- String.class, aQualifiedContextName);
- ((Map) mInternalResourceRegistrationMap).put(name, reg);
-
- // Perform binding
- if (isAutowireEnabled()) {
- mResourceMap.put(aQualifiedContextName + name, context.getBean(name));
- }
- }
- catch (Exception e1) {
- throw new ResourceInitializationException(e1);
- }
- }
- else {
- try {
- Object desc = getFieldValue(registration, "description");
-
- if (desc != null) {
- String definingContext = getFieldValue(registration, "definingContext");
-
- if (aQualifiedContextName.startsWith(definingContext)) {
- UIMAFramework.getLogger().logrb(
- Level.CONFIG,
- ResourceManager_impl.class.getName(),
- "initializeExternalResources",
- LOG_RESOURCE_BUNDLE,
- "UIMA_overridden_resource__CONFIG",
- new Object[] { name, aQualifiedContextName,
- definingContext });
- }
- else {
- UIMAFramework.getLogger().logrb(
- Level.WARNING,
- ResourceManager_impl.class.getName(),
- "initializeExternalResources",
- LOG_RESOURCE_BUNDLE,
- "UIMA_duplicate_resource_name__WARNING",
- new Object[] { name, definingContext,
- aQualifiedContextName });
- }
- }
- }
- catch (Exception e1) {
- throw new ResourceInitializationException(e1);
- }
- }
- }
-
- super.initializeExternalResources(aConfiguration, aQualifiedContextName, aAdditionalParams);
- }
-
- public void setApplicationContext(ApplicationContext aApplicationContext)
- throws BeansException
- {
- context = aApplicationContext;
- }
-
- /**
- * Instantiate a non-visible class.
- */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private static <T> T newInstance(String aClassName, Object... aArgs) throws ResourceInitializationException {
- Constructor constr = null;
- try {
- Class<?> cl = Class.forName(aClassName);
-
- List<Class> types = new ArrayList<Class>();
- List<Object> values = new ArrayList<Object>();
- for (int i = 0; i < aArgs.length; i += 2) {
- types.add((Class) aArgs[i]);
- values.add(aArgs[i+1]);
- }
-
- constr = cl.getDeclaredConstructor(types.toArray(new Class[types.size()]));
- constr.setAccessible(true);
- return (T) constr.newInstance(values.toArray(new Object[values.size()]));
- }
- catch (Exception e) {
- throw new ResourceInitializationException(e);
- }
- finally {
- if (constr != null) {
- constr.setAccessible(false);
- }
- }
- }
-
- /**
- * Get a field value from a non-visible field.
- */
- @SuppressWarnings("unchecked")
- private static <T> T getFieldValue(Object aObject, String aFieldName)
- {
- return (T) PropertyAccessorFactory.forDirectFieldAccess(aObject).getPropertyValue(aFieldName);
- }
-
- public void setAutowireEnabled(boolean aAutowireEnabled)
- {
- autowireEnabled = aAutowireEnabled;
- }
-
- public boolean isAutowireEnabled()
- {
- return autowireEnabled;
- }
+public class SpringContextResourceManager extends ResourceManager_impl implements
+ ApplicationContextAware {
+ private ApplicationContext context;
+
+ private boolean autowireEnabled = false;
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public void initializeExternalResources(ResourceManagerConfiguration aConfiguration,
+ String aQualifiedContextName, java.util.Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+
+ for (String name : BeanFactoryUtils.beanNamesIncludingAncestors(context)) {
+ Object registration = mInternalResourceRegistrationMap.get(name);
+
+ if (registration == null) {
+ try {
+ // Register resource
+ // ResourceRegistration unfortunately is package private
+ Object reg = newInstance(
+ "org.apache.uima.resource.impl.ResourceManager_impl$ResourceRegistration",
+ Object.class, context.getBean(name), ExternalResourceDescription.class, null,
+ String.class, aQualifiedContextName);
+ ((Map) mInternalResourceRegistrationMap).put(name, reg);
+
+ // Perform binding
+ if (isAutowireEnabled()) {
+ mResourceMap.put(aQualifiedContextName + name, context.getBean(name));
+ }
+ } catch (Exception e1) {
+ throw new ResourceInitializationException(e1);
+ }
+ } else {
+ try {
+ Object desc = getFieldValue(registration, "description");
+
+ if (desc != null) {
+ String definingContext = getFieldValue(registration, "definingContext");
+
+ if (aQualifiedContextName.startsWith(definingContext)) {
+ UIMAFramework.getLogger().logrb(Level.CONFIG, ResourceManager_impl.class.getName(),
+ "initializeExternalResources", LOG_RESOURCE_BUNDLE,
+ "UIMA_overridden_resource__CONFIG",
+ new Object[] { name, aQualifiedContextName, definingContext });
+ } else {
+ UIMAFramework.getLogger().logrb(Level.WARNING, ResourceManager_impl.class.getName(),
+ "initializeExternalResources", LOG_RESOURCE_BUNDLE,
+ "UIMA_duplicate_resource_name__WARNING",
+ new Object[] { name, definingContext, aQualifiedContextName });
+ }
+ }
+ } catch (Exception e1) {
+ throw new ResourceInitializationException(e1);
+ }
+ }
+ }
+
+ super.initializeExternalResources(aConfiguration, aQualifiedContextName, aAdditionalParams);
+ }
+
+ public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
+ context = aApplicationContext;
+ }
+
+ /**
+ * Instantiate a non-visible class.
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private static <T> T newInstance(String aClassName, Object... aArgs)
+ throws ResourceInitializationException {
+ Constructor constr = null;
+ try {
+ Class<?> cl = Class.forName(aClassName);
+
+ List<Class> types = new ArrayList<Class>();
+ List<Object> values = new ArrayList<Object>();
+ for (int i = 0; i < aArgs.length; i += 2) {
+ types.add((Class) aArgs[i]);
+ values.add(aArgs[i + 1]);
+ }
+
+ constr = cl.getDeclaredConstructor(types.toArray(new Class[types.size()]));
+ constr.setAccessible(true);
+ return (T) constr.newInstance(values.toArray(new Object[values.size()]));
+ } catch (Exception e) {
+ throw new ResourceInitializationException(e);
+ } finally {
+ if (constr != null) {
+ constr.setAccessible(false);
+ }
+ }
+ }
+
+ /**
+ * Get a field value from a non-visible field.
+ */
+ @SuppressWarnings("unchecked")
+ private static <T> T getFieldValue(Object aObject, String aFieldName) {
+ return (T) PropertyAccessorFactory.forDirectFieldAccess(aObject).getPropertyValue(aFieldName);
+ }
+
+ public void setAutowireEnabled(boolean aAutowireEnabled) {
+ autowireEnabled = aAutowireEnabled;
+ }
+
+ public boolean isAutowireEnabled() {
+ return autowireEnabled;
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/AnalysisEngineFactory_impl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/AnalysisEngineFactory_impl.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/AnalysisEngineFactory_impl.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/AnalysisEngineFactory_impl.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring.factory;
import static org.apache.uima.fit.spring.util.ResourceInitializationUtil.initResource;
@@ -34,18 +33,18 @@ import org.springframework.context.Appli
/**
*/
public class AnalysisEngineFactory_impl extends org.apache.uima.impl.AnalysisEngineFactory_impl
- implements ApplicationContextAware {
- private ApplicationContext applicationContext;
+ implements ApplicationContextAware {
+ private ApplicationContext applicationContext;
- public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
- applicationContext = aApplicationContext;
- }
-
- @Override
- public Resource produceResource(Class<? extends Resource> aResourceClass,
- ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
- throws ResourceInitializationException {
- Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
- return initResource(resource, applicationContext);
- }
+ public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
+ applicationContext = aApplicationContext;
+ }
+
+ @Override
+ public Resource produceResource(Class<? extends Resource> aResourceClass,
+ ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+ Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
+ return initResource(resource, applicationContext);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasConsumerFactory_impl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasConsumerFactory_impl.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasConsumerFactory_impl.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasConsumerFactory_impl.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring.factory;
import static org.apache.uima.fit.spring.util.ResourceInitializationUtil.initResource;
@@ -33,24 +32,19 @@ import org.springframework.context.Appli
/**
*/
-public class CasConsumerFactory_impl
- extends org.apache.uima.impl.CasConsumerFactory_impl
- implements ApplicationContextAware
-{
- private ApplicationContext applicationContext;
-
- public void setApplicationContext(ApplicationContext aApplicationContext)
- throws BeansException
- {
- applicationContext = aApplicationContext;
- }
-
- @Override
- public Resource produceResource(Class<? extends Resource> aResourceClass,
- ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
- throws ResourceInitializationException
- {
- Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
- return initResource(resource, applicationContext);
- }
+public class CasConsumerFactory_impl extends org.apache.uima.impl.CasConsumerFactory_impl implements
+ ApplicationContextAware {
+ private ApplicationContext applicationContext;
+
+ public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
+ applicationContext = aApplicationContext;
+ }
+
+ @Override
+ public Resource produceResource(Class<? extends Resource> aResourceClass,
+ ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+ Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
+ return initResource(resource, applicationContext);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasInitializerFactory_impl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasInitializerFactory_impl.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasInitializerFactory_impl.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CasInitializerFactory_impl.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring.factory;
import static org.apache.uima.fit.spring.util.ResourceInitializationUtil.initResource;
@@ -34,25 +33,20 @@ import org.springframework.context.Appli
/**
*/
@Deprecated
-public class CasInitializerFactory_impl
- extends org.apache.uima.impl.CasInitializerFactory_impl
- implements ApplicationContextAware
-{
- private ApplicationContext applicationContext;
-
- public void setApplicationContext(ApplicationContext aApplicationContext)
- throws BeansException
- {
- applicationContext = aApplicationContext;
- }
-
- @Override
- public Resource produceResource(Class<? extends Resource> aResourceClass,
- ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
- throws ResourceInitializationException
- {
- Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
- return initResource(resource, applicationContext);
- }
+public class CasInitializerFactory_impl extends org.apache.uima.impl.CasInitializerFactory_impl
+ implements ApplicationContextAware {
+ private ApplicationContext applicationContext;
+
+ public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
+ applicationContext = aApplicationContext;
+ }
+
+ @Override
+ public Resource produceResource(Class<? extends Resource> aResourceClass,
+ ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+ Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
+ return initResource(resource, applicationContext);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CollectionReaderFactory_impl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CollectionReaderFactory_impl.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CollectionReaderFactory_impl.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CollectionReaderFactory_impl.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring.factory;
import static org.apache.uima.fit.spring.util.ResourceInitializationUtil.initResource;
@@ -33,25 +32,20 @@ import org.springframework.context.Appli
/**
*/
-public class CollectionReaderFactory_impl
- extends org.apache.uima.impl.CollectionReaderFactory_impl
- implements ApplicationContextAware
-{
- private ApplicationContext applicationContext;
-
- public void setApplicationContext(ApplicationContext aApplicationContext)
- throws BeansException
- {
- applicationContext = aApplicationContext;
- }
-
- @Override
- public Resource produceResource(Class<? extends Resource> aResourceClass,
- ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
- throws ResourceInitializationException
- {
- Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
- return initResource(resource, applicationContext);
- }
+public class CollectionReaderFactory_impl extends org.apache.uima.impl.CollectionReaderFactory_impl
+ implements ApplicationContextAware {
+ private ApplicationContext applicationContext;
+
+ public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
+ applicationContext = aApplicationContext;
+ }
+
+ @Override
+ public Resource produceResource(Class<? extends Resource> aResourceClass,
+ ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+ Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
+ return initResource(resource, applicationContext);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CustomResourceFactory_impl.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CustomResourceFactory_impl.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CustomResourceFactory_impl.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/factory/CustomResourceFactory_impl.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring.factory;
import static org.apache.uima.fit.spring.util.ResourceInitializationUtil.initResource;
@@ -33,24 +32,19 @@ import org.springframework.context.Appli
/**
*/
-public class CustomResourceFactory_impl
- extends org.apache.uima.impl.CustomResourceFactory_impl
- implements ApplicationContextAware
-{
- private ApplicationContext applicationContext;
-
- public void setApplicationContext(ApplicationContext aApplicationContext)
- throws BeansException
- {
- applicationContext = aApplicationContext;
- }
-
- @Override
- public Resource produceResource(Class<? extends Resource> aResourceClass,
- ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
- throws ResourceInitializationException
- {
- Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
- return initResource(resource, applicationContext);
- }
+public class CustomResourceFactory_impl extends org.apache.uima.impl.CustomResourceFactory_impl
+ implements ApplicationContextAware {
+ private ApplicationContext applicationContext;
+
+ public void setApplicationContext(ApplicationContext aApplicationContext) throws BeansException {
+ applicationContext = aApplicationContext;
+ }
+
+ @Override
+ public Resource produceResource(Class<? extends Resource> aResourceClass,
+ ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+ Resource resource = super.produceResource(aResourceClass, aSpecifier, aAdditionalParams);
+ return initResource(resource, applicationContext);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/util/ResourceInitializationUtil.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/util/ResourceInitializationUtil.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/util/ResourceInitializationUtil.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/main/java/org/apache/uima/fit/spring/util/ResourceInitializationUtil.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring.util;
import org.apache.uima.analysis_component.AnalysisComponent;
@@ -31,40 +30,35 @@ import org.springframework.context.Appli
/**
*/
public class ResourceInitializationUtil {
- /**
- * Initialize an existing object as a Spring bean.
- */
- public static <T> T initializeBean(AutowireCapableBeanFactory aBeanFactory, T aBean,
- String aName) {
- @SuppressWarnings("unchecked")
- T wrappedBean = (T) aBeanFactory.initializeBean(aBean, aName);
- aBeanFactory.autowireBean(aBean);
- return wrappedBean;
- }
-
- /**
- * Handle Spring-initialization of resoures produced by the UIMA framework.
- */
- public static Resource initResource(Resource aResource,
- ApplicationContext aApplicationContext) {
- AutowireCapableBeanFactory beanFactory = aApplicationContext
- .getAutowireCapableBeanFactory();
-
- if (aResource instanceof PrimitiveAnalysisEngine_impl) {
- PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(aResource);
-
- // Access the actual AnalysisComponent and initialize it
- AnalysisComponent analysisComponent = (AnalysisComponent) pa
- .getPropertyValue("mAnalysisComponent");
- initializeBean(beanFactory, analysisComponent, aResource.getMetaData().getName());
- pa.setPropertyValue("mAnalysisComponent", analysisComponent);
-
- return aResource;
- }
- else {
- return (Resource) beanFactory
- .initializeBean(aResource, aResource.getMetaData().getName());
- }
- }
+ /**
+ * Initialize an existing object as a Spring bean.
+ */
+ public static <T> T initializeBean(AutowireCapableBeanFactory aBeanFactory, T aBean, String aName) {
+ @SuppressWarnings("unchecked")
+ T wrappedBean = (T) aBeanFactory.initializeBean(aBean, aName);
+ aBeanFactory.autowireBean(aBean);
+ return wrappedBean;
+ }
+
+ /**
+ * Handle Spring-initialization of resoures produced by the UIMA framework.
+ */
+ public static Resource initResource(Resource aResource, ApplicationContext aApplicationContext) {
+ AutowireCapableBeanFactory beanFactory = aApplicationContext.getAutowireCapableBeanFactory();
+
+ if (aResource instanceof PrimitiveAnalysisEngine_impl) {
+ PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(aResource);
+
+ // Access the actual AnalysisComponent and initialize it
+ AnalysisComponent analysisComponent = (AnalysisComponent) pa
+ .getPropertyValue("mAnalysisComponent");
+ initializeBean(beanFactory, analysisComponent, aResource.getMetaData().getName());
+ pa.setPropertyValue("mAnalysisComponent", analysisComponent);
+
+ return aResource;
+ } else {
+ return (Resource) beanFactory.initializeBean(aResource, aResource.getMetaData().getName());
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/SpringContextResourceManagerTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/SpringContextResourceManagerTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/SpringContextResourceManagerTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/SpringContextResourceManagerTest.java Thu Jan 10 23:12:33 2013
@@ -17,11 +17,10 @@
* under the License.
*/
-
package org.apache.uima.fit.spring;
import static org.apache.uima.fit.factory.AnalysisEngineFactory.createPrimitiveDescription;
-import static org.apache.uima.fit.factory.ExternalResourceFactory.*;
+import static org.apache.uima.fit.factory.ExternalResourceFactory.bindExternalResource;
import static org.junit.Assert.assertEquals;
import org.apache.uima.UIMAFramework;
@@ -30,7 +29,6 @@ import org.apache.uima.analysis_engine.A
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.descriptor.ExternalResource;
-import org.apache.uima.fit.spring.SpringContextResourceManager;
import org.apache.uima.jcas.JCas;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -40,52 +38,51 @@ import org.springframework.context.suppo
/**
* Test making Spring beans available to a UIMA component via the resource manager.
- *
+ *
*/
public class SpringContextResourceManagerTest {
- // Allow UIMA components to be configured with beans from a Spring context
+ // Allow UIMA components to be configured with beans from a Spring context
- // Allow the construction of UIMA components as Spring beans. This means:
- // - UIMA AnalysisComponent
+ // Allow the construction of UIMA components as Spring beans. This means:
+ // - UIMA AnalysisComponent
- @Test
- public void test() throws Exception {
- // Acquire application context
- ApplicationContext ctx = getApplicationContext();
-
- // Create resource manager
- SpringContextResourceManager resMgr = new SpringContextResourceManager();
- resMgr.setApplicationContext(ctx);
-
- // Create component description
- AnalysisEngineDescription desc = createPrimitiveDescription(MyAnalysisEngine.class);
- bindExternalResource(desc, "injectedBean", "springBean");
-
- // Instantiate component
- AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
-
- // Test that injection works
- ae.process(ae.newJCas());
- }
-
- public static class MyAnalysisEngine extends JCasAnnotator_ImplBase {
- @ExternalResource(key = "injectedBean")
- private Object injectedBean;
-
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- assertEquals("BEAN", injectedBean);
- }
- }
-
- private ApplicationContext getApplicationContext() {
- final GenericApplicationContext ctx = new GenericApplicationContext();
- AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
- ctx.registerBeanDefinition(
- "springBean",
- BeanDefinitionBuilder.genericBeanDefinition(String.class)
- .addConstructorArgValue("BEAN").getBeanDefinition());
- ctx.refresh();
- return ctx;
- }
+ @Test
+ public void test() throws Exception {
+ // Acquire application context
+ ApplicationContext ctx = getApplicationContext();
+
+ // Create resource manager
+ SpringContextResourceManager resMgr = new SpringContextResourceManager();
+ resMgr.setApplicationContext(ctx);
+
+ // Create component description
+ AnalysisEngineDescription desc = createPrimitiveDescription(MyAnalysisEngine.class);
+ bindExternalResource(desc, "injectedBean", "springBean");
+
+ // Instantiate component
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
+
+ // Test that injection works
+ ae.process(ae.newJCas());
+ }
+
+ public static class MyAnalysisEngine extends JCasAnnotator_ImplBase {
+ @ExternalResource(key = "injectedBean")
+ private Object injectedBean;
+
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ assertEquals("BEAN", injectedBean);
+ }
+ }
+
+ private ApplicationContext getApplicationContext() {
+ final GenericApplicationContext ctx = new GenericApplicationContext();
+ AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
+ ctx.registerBeanDefinition("springBean",
+ BeanDefinitionBuilder.genericBeanDefinition(String.class)
+ .addConstructorArgValue("BEAN").getBeanDefinition());
+ ctx.refresh();
+ return ctx;
+ }
}