Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
kallimachos
KallimachosPythonUIMAEngines
Commits
47f38b77
Commit
47f38b77
authored
Feb 21, 2017
by
Markus Krug
Browse files
initial upload of the engine
parents
Changes
5
Hide whitespace changes
Inline
Side-by-side
sentimentAnalysis/pom.xml
0 → 100644
View file @
47f38b77
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
de.uniwue.az.sentiment
</groupId>
<artifactId>
sentimentAnalysis
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<dependencies>
<dependency>
<groupId>
org.apache.uima
</groupId>
<artifactId>
uimaj-core
</artifactId>
<version>
2.9.0
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.apache.uima
</groupId>
<artifactId>
uimafit-core
</artifactId>
<version>
2.2.0
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
de.uniwue.mk.nappi
</groupId>
<artifactId>
de.uniwue.mk.nappi.serviceprovider
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>
maven-assembly-plugin
</artifactId>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
single
</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.1
</version>
<configuration>
<!-- or whatever version you use -->
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
sentimentAnalysis/src/main/java/sentimentAnalysis/engine/KallimachosSentimentAnalysisEngine.java
0 → 100644
View file @
47f38b77
package
sentimentAnalysis.engine
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.uima.UimaContext
;
import
org.apache.uima.analysis_engine.AnalysisEngineProcessException
;
import
org.apache.uima.cas.CAS
;
import
org.apache.uima.cas.TypeSystem
;
import
org.apache.uima.cas.impl.TypeSystem2Xml
;
import
org.apache.uima.cas.impl.XmiCasDeserializer
;
import
org.apache.uima.cas.impl.XmiCasSerializer
;
import
org.apache.uima.fit.component.JCasAnnotator_ImplBase
;
import
org.apache.uima.fit.descriptor.ConfigurationParameter
;
import
org.apache.uima.jcas.JCas
;
import
org.apache.uima.resource.ResourceInitializationException
;
import
org.xml.sax.SAXException
;
public
class
KallimachosSentimentAnalysisEngine
extends
JCasAnnotator_ImplBase
{
private
File
xmiFile
;
private
File
typeSystemFile
;
/**
* The location of the model.
*/
public
static
final
String
PARAM_SCRIPT_LOCATION
=
"PARAM_SCRIPT_LOCATION"
;
@ConfigurationParameter
(
name
=
PARAM_SCRIPT_LOCATION
,
mandatory
=
true
)
private
String
scriptLocationParam
;
private
String
scriptLocation
;
@Override
public
void
initialize
(
UimaContext
context
)
throws
ResourceInitializationException
{
// set the temporary file for the features
try
{
xmiFile
=
File
.
createTempFile
(
"tempXMIPyCAS"
,
".xmi"
);
typeSystemFile
=
File
.
createTempFile
(
"TypeSystem"
,
"CorefTypeSystem.xml"
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
xmiFile
.
deleteOnExit
();
typeSystemFile
.
deleteOnExit
();
scriptLocation
=
(
String
)
context
.
getConfigParameterValue
(
PARAM_SCRIPT_LOCATION
);
super
.
initialize
(
context
);
}
@Override
public
void
process
(
JCas
jCas
)
throws
AnalysisEngineProcessException
{
CAS
cas
=
jCas
.
getCas
();
// serialite TS
serializeTS
(
cas
);
// serializie CAS
serializeXMI
(
cas
);
// process the script
try
{
String
command
=
"python "
+
scriptLocation
+
" "
+
xmiFile
.
getAbsolutePath
()
+
" "
+
typeSystemFile
.
getAbsolutePath
()
+
" "
+
xmiFile
.
getAbsolutePath
();
Process
exec
=
Runtime
.
getRuntime
().
exec
(
command
);
// output both stdout and stderr data from proc to stdout of this
// process
StreamGobbler
errorGobbler
=
new
StreamGobbler
(
exec
.
getErrorStream
());
StreamGobbler
outputGobbler
=
new
StreamGobbler
(
exec
.
getInputStream
());
errorGobbler
.
start
();
outputGobbler
.
start
();
exec
.
waitFor
();
exec
.
destroy
();
System
.
out
.
println
(
command
);
}
catch
(
IOException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
try
{
XmiCasDeserializer
.
deserialize
(
new
FileInputStream
(
xmiFile
),
cas
);
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
SAXException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
xmiFile
.
delete
();
typeSystemFile
.
delete
();
}
private
void
serializeXMI
(
CAS
cas
)
{
try
{
FileOutputStream
aStream
=
new
FileOutputStream
(
xmiFile
);
XmiCasSerializer
.
serialize
(
cas
,
aStream
);
aStream
.
flush
();
aStream
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
SAXException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
private
void
serializeTS
(
CAS
cas
)
{
try
{
TypeSystem
typeSystem
=
cas
.
getTypeSystem
();
FileOutputStream
aOutputStream
=
new
FileOutputStream
(
typeSystemFile
);
TypeSystem2Xml
.
typeSystem2Xml
(
typeSystem
,
aOutputStream
);
aOutputStream
.
flush
();
aOutputStream
.
close
();
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
SAXException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
@Override
public
void
collectionProcessComplete
()
throws
AnalysisEngineProcessException
{
super
.
collectionProcessComplete
();
xmiFile
.
delete
();
typeSystemFile
.
delete
();
}
}
sentimentAnalysis/src/main/java/sentimentAnalysis/engine/SentimentDetectionAnalysisEngineService.java
0 → 100644
View file @
47f38b77
package
sentimentAnalysis.engine
;
import
de.uniwue.mk.nappi.serviceprovider.aeservice.IAnalysisEngineService
;
public
class
SentimentDetectionAnalysisEngineService
implements
IAnalysisEngineService
{
public
Class
<
KallimachosSentimentAnalysisEngine
>
getAnalysisEngine
()
{
return
KallimachosSentimentAnalysisEngine
.
class
;
}
}
sentimentAnalysis/src/main/java/sentimentAnalysis/engine/StreamGobbler.java
0 → 100644
View file @
47f38b77
package
sentimentAnalysis.engine
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
class
StreamGobbler
extends
Thread
{
InputStream
is
;
// reads everything from is until empty.
StreamGobbler
(
InputStream
is
)
{
this
.
is
=
is
;
}
public
void
run
()
{
try
{
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
String
line
=
null
;
while
(
(
line
=
br
.
readLine
())
!=
null
)
System
.
out
.
println
(
line
);
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
}
}
\ No newline at end of file
sentimentAnalysis/src/main/resources/META-INF/services/de.uniwue.mk.nappi.serviceprovider.aeservice.IAnalysisEngineService
0 → 100644
View file @
47f38b77
sentimentAnalysis.engine.SentimentDetectionAnalysisEngineService
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment