Skip to content

Commit 39e1a1c

Browse files
committed
add more AEs to code/
1 parent b6cc465 commit 39e1a1c

File tree

222 files changed

+27074
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+27074
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
3+
<frameworkImplementation>org.apache.uima.java</frameworkImplementation>
4+
<primitive>true</primitive>
5+
<annotatorImplementationName>org.barcelonamedia.uima.csvMetadataAnnotator.CSVMetadataAnnotator</annotatorImplementationName>
6+
<analysisEngineMetaData>
7+
<name>CSVMetadataAnnotator</name>
8+
<description/>
9+
<version>1.0</version>
10+
<vendor/>
11+
<configurationParameters>
12+
<configurationParameter>
13+
<name>CSV_File_URI</name>
14+
<type>String</type>
15+
<multiValued>false</multiValued>
16+
<mandatory>true</mandatory>
17+
</configurationParameter>
18+
<configurationParameter>
19+
<name>field_separator</name>
20+
<description>The accepted values are comma, space or tab</description>
21+
<type>String</type>
22+
<multiValued>false</multiValued>
23+
<mandatory>false</mandatory>
24+
</configurationParameter>
25+
</configurationParameters>
26+
<configurationParameterSettings>
27+
<nameValuePair>
28+
<name>CSV_File_URI</name>
29+
<value>
30+
<string>C:\Users\david.garcian\Documents\Mis archivos\UIMA\workspace\CSVMetadataAnnotator\resources\csv\twitter-test-input-A.csv</string>
31+
</value>
32+
</nameValuePair>
33+
</configurationParameterSettings>
34+
<typeSystemDescription>
35+
<imports>
36+
<import name="bm-opinion-types"/>
37+
<import name="bm-semantics-types"/>
38+
<import name="bm-syntax-types"/>
39+
<import name="bm-web-types"/>
40+
<import name="bm-Wikipedia-types"/>
41+
<import name="org.apache.uima.examples.SourceDocumentInformation"/>
42+
</imports>
43+
</typeSystemDescription>
44+
<typePriorities/>
45+
<fsIndexCollection/>
46+
<capabilities>
47+
<capability>
48+
<inputs/>
49+
<outputs/>
50+
<languagesSupported/>
51+
</capability>
52+
</capabilities>
53+
<operationalProperties>
54+
<modifiesCas>true</modifiesCas>
55+
<multipleDeploymentAllowed>true</multipleDeploymentAllowed>
56+
<outputsNewCASes>false</outputsNewCASes>
57+
</operationalProperties>
58+
</analysisEngineMetaData>
59+
<resourceManagerConfiguration/>
60+
</analysisEngineDescription>

code/CSVMetadataAnnotator/pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<project
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.barcelonamedia.uima</groupId>
8+
<artifactId>uima-pears</artifactId>
9+
<version>0.1.3</version>
10+
</parent>
11+
12+
<groupId>org.barcelonamedia.uima</groupId>
13+
<artifactId>CSVMetadataAnnotator</artifactId>
14+
<version>0.1.2</version>
15+
<name>CSVMetadataAnnotator</name>
16+
<repositories>
17+
<repository>
18+
<id>functional-java</id>
19+
<name>Functional Java</name>
20+
<url>http://functionaljava.googlecode.com/svn/maven</url>
21+
</repository>
22+
</repositories>
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.apache.uima</groupId>
26+
<artifactId>uimaj-core</artifactId>
27+
<version>2.4.0</version>
28+
<scope>provided</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>net.sf.opencsv</groupId>
32+
<artifactId>opencsv</artifactId>
33+
<version>2.3</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.google.collections</groupId>
37+
<artifactId>google-collections</artifactId>
38+
<version>[0.9, 2.0)</version>
39+
</dependency>
40+
</dependencies>
41+
<build>
42+
<plugins>
43+
</plugins>
44+
</build>
45+
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.apache.uima.examples.SourceDocumentInformation:uri,org.barcelonamedia.uima.ts.opinion.Polar:polarity,org.barcelonamedia.uima.ts.opinion.Polar:begin,org.barcelonamedia.uima.ts.opinion.Polar:end
2+
file:/C:/Users/david.garcian/Documents/Mis archivos/UIMA/input/1.txt,N,0,5
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package org.barcelonamedia.uima.csvMetadataAnnotator;
2+
3+
import java.io.FileNotFoundException;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
import java.util.HashMap;
7+
import java.util.Iterator;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
import org.apache.uima.UimaContext;
12+
import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
13+
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
14+
import org.apache.uima.cas.FSIterator;
15+
import org.apache.uima.cas.Feature;
16+
import org.apache.uima.cas.Type;
17+
import org.apache.uima.cas.text.AnnotationIndex;
18+
import org.apache.uima.jcas.JCas;
19+
import org.apache.uima.jcas.tcas.Annotation;
20+
import org.apache.uima.resource.ResourceInitializationException;
21+
import org.apache.uima.util.Level;
22+
import org.apache.uima.util.Logger;
23+
24+
import com.google.common.collect.ImmutableMap;
25+
26+
import au.com.bytecode.opencsv.CSVReader;
27+
28+
29+
public class CSVMetadataAnnotator extends JCasAnnotator_ImplBase {
30+
31+
private static final String DESCRIPTOR_NAME = "org.barcelonamedia.uima.csvMetadataAnnotator";
32+
private static final String CSV_FILE_URI_PARAM = "CSV_File_URI";
33+
private static final String SEPARATOR_PARAM = "field_separator";
34+
35+
private final static ImmutableMap<String, Character> SEPARATOR_MAP = new ImmutableMap.Builder<String, Character>()
36+
.put("comma", new Character(','))
37+
.put("tab", new Character('\t'))
38+
.put("space", new Character(' '))
39+
.build();
40+
private Logger logger;
41+
private MetadataMap map;
42+
private boolean copyOffset;
43+
44+
45+
public void initialize(UimaContext aContext) throws ResourceInitializationException{
46+
47+
super.initialize(aContext);
48+
49+
logger = aContext.getLogger();
50+
51+
String separator_param = (String) aContext.getConfigParameterValue(SEPARATOR_PARAM);
52+
Character separator = SEPARATOR_MAP.get(separator_param);
53+
54+
String csvFileURI = (String) aContext.getConfigParameterValue(CSV_FILE_URI_PARAM);
55+
56+
try{
57+
58+
CSVReader csvReader;
59+
60+
if(separator == null){
61+
62+
csvReader = new CSVReader(new FileReader(csvFileURI));
63+
}
64+
else{
65+
66+
csvReader = new CSVReader(new FileReader(csvFileURI), separator.charValue());
67+
}
68+
69+
logger.log(Level.INFO, "csv - initialize - csv file loaded");
70+
71+
try{
72+
73+
map = new MetadataMap(csvReader);
74+
75+
System.out.println("Map:");
76+
77+
Iterator it = map.entrySet().iterator();
78+
while (it.hasNext()) {
79+
Map.Entry pairs = (Map.Entry)it.next();
80+
System.out.println(pairs.getKey() + " = " + pairs.getValue());
81+
}
82+
83+
System.out.println("__________");
84+
}
85+
catch(IOException e){
86+
87+
logger.log(Level.SEVERE, e.getMessage());
88+
throw new ResourceInitializationException(e);
89+
}
90+
91+
logger.log(Level.INFO, "csv - initialize - csv file processed");
92+
93+
}
94+
catch (FileNotFoundException e){
95+
96+
logger.log(Level.SEVERE, e.getMessage());
97+
throw new ResourceInitializationException(e);
98+
}
99+
}
100+
101+
public void process(JCas jCas) throws AnalysisEngineProcessException{
102+
103+
String filterTypename = map.getFilterTypename();
104+
String featureName = map.getFeatureName();
105+
106+
if(filterTypename != null && featureName != null){
107+
108+
Type filterType = jCas.getTypeSystem().getType(filterTypename);
109+
110+
if(filterType == null){
111+
112+
String[] arguments = {filterTypename, DESCRIPTOR_NAME};
113+
throw new AnalysisEngineProcessException("class_not_found", arguments);
114+
}
115+
116+
Feature filterFeature = filterType.getFeatureByBaseName(featureName);
117+
118+
if(filterFeature == null){
119+
120+
String[] arguments = {featureName, filterTypename};
121+
throw new AnalysisEngineProcessException("UNDEFINED_FEATURE", arguments);
122+
}
123+
124+
AnnotationIndex<Annotation> index = jCas.getAnnotationIndex(filterType);
125+
FSIterator<Annotation> iter = index.iterator();
126+
127+
String annotationTypename;
128+
Type annotationType;
129+
Annotation annotation;
130+
131+
while(iter.hasNext()){
132+
133+
Annotation annot = iter.next();
134+
String filterFeatureValue = annot.getFeatureValueAsString(filterFeature);
135+
136+
List<Metadata> metadataList = map.get(filterFeatureValue);
137+
138+
if(metadataList != null){
139+
140+
for(Metadata meta: metadataList){
141+
142+
annotationTypename = meta.getAnnotationType();
143+
annotationType = jCas.getTypeSystem().getType(annotationTypename);
144+
145+
if(annotationType == null){
146+
147+
String[] arguments = {annotationTypename, DESCRIPTOR_NAME};
148+
throw new AnalysisEngineProcessException("class_not_found", arguments);
149+
}
150+
151+
//copyOffset is never initialised
152+
if(copyOffset){
153+
154+
annotation = (Annotation) jCas.getCas().createAnnotation(annotationType, annot.getBegin(), annot.getEnd());
155+
}
156+
else{
157+
158+
annotation = (Annotation) jCas.getCas().createAnnotation(annotationType, 0, 0);
159+
}
160+
161+
HashMap<String, String> featuresQualifiedName = meta.getFeaturesQualifiedName();
162+
Iterator<Map.Entry<String, String>> iterator = featuresQualifiedName.entrySet().iterator();
163+
164+
while(iterator.hasNext()){
165+
166+
Map.Entry<String, String> pairs = (Map.Entry<String, String>)iterator.next();
167+
168+
String featureQualifiedName = (String)pairs.getKey();
169+
String featureValue = (String)pairs.getValue();
170+
171+
Feature feature = jCas.getCas().getTypeSystem().getFeatureByFullName(featureQualifiedName);
172+
173+
annotation.setFeatureValueFromString(feature, featureValue);
174+
}
175+
176+
annotation.addToIndexes();
177+
}
178+
}
179+
}
180+
}
181+
}
182+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.barcelonamedia.uima.csvMetadataAnnotator;
2+
3+
import java.util.HashMap;
4+
5+
6+
public class Metadata{
7+
8+
private String annotationType;
9+
private HashMap<String, String> featuresQualifiedName;
10+
11+
12+
public Metadata(String annotationType, HashMap<String, String> featuresQualifiedName){
13+
14+
this.annotationType = annotationType;
15+
this.featuresQualifiedName = featuresQualifiedName;
16+
}
17+
18+
public String getAnnotationType(){
19+
20+
return this.annotationType;
21+
}
22+
23+
public void setAnnotationType(String annotationType){
24+
25+
this.annotationType = annotationType;
26+
}
27+
28+
public HashMap<String, String> getFeaturesQualifiedName(){
29+
30+
return this.featuresQualifiedName;
31+
}
32+
33+
public void setFeaturesQualifiedName(HashMap<String, String> featuresQualifiedName){
34+
35+
this.featuresQualifiedName = featuresQualifiedName;
36+
}
37+
}

0 commit comments

Comments
 (0)