You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by st...@apache.org on 2012/11/20 13:03:30 UTC
svn commit: r1411634 - in /incubator/ctakes/trunk:
ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java
ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEKnowtatorXMLReader.java
Author: stevenbethard
Date: Tue Nov 20 12:03:29 2012
New Revision: 1411634
URL: http://svn.apache.org/viewvc?rev=1411634&view=rev
Log:
Fixes THYMEKnowtatorXMLReader to handle recent changes to SHARPKnowtatorXMLReader.
Modified:
incubator/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java
incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEKnowtatorXMLReader.java
Modified: incubator/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java?rev=1411634&r1=1411633&r2=1411634&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java (original)
+++ incubator/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/ae/SHARPKnowtatorXMLReader.java Tue Nov 20 12:03:29 2012
@@ -72,15 +72,22 @@ import org.uimafit.util.JCasUtil;
public class SHARPKnowtatorXMLReader extends JCasAnnotator_ImplBase {
static Logger LOGGER = Logger.getLogger(SHARPKnowtatorXMLReader.class);
- private static String getJCasURIString(JCas jCas) {
- return JCasUtil.selectSingle(jCas, DocumentID.class).getDocumentID();
+ /**
+ * Get the URI that the text in this class was loaded from
+ */
+ protected URI getTextURI(JCas jCas) throws AnalysisEngineProcessException {
+ try {
+ return new URI(JCasUtil.selectSingle(jCas, DocumentID.class).getDocumentID());
+ } catch (URISyntaxException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
}
/**
- * Given the URI of the plain text file, determines the URI of the Knowtator XML file
+ * Get the URI for the Knowtator XML file that should be loaded
*/
- protected URI getKnowtatorXML(JCas jCas) throws AnalysisEngineProcessException {
- String textURI = getJCasURIString(jCas);
+ protected URI getKnowtatorURI(JCas jCas) throws AnalysisEngineProcessException {
+ String textURI = this.getTextURI(jCas).toString();
String xmlURI = textURI.replaceAll("Knowtator/text", "Knowtator_XML") + ".knowtator.xml";
try {
return new URI(xmlURI);
@@ -98,12 +105,13 @@ public class SHARPKnowtatorXMLReader ext
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
+ URI textURI = this.getTextURI(jCas);
+ LOGGER.info("processing " + textURI);
+
// determine Knowtator XML file from the CAS
- String uriString = getJCasURIString(jCas);
- LOGGER.info("processing " + uriString);
- URI knowtatorXML = this.getKnowtatorXML(jCas);
- if (!new File(knowtatorXML).exists()) {
- LOGGER.fatal("no such Knowtator XML file " + knowtatorXML);
+ URI knowtatorURI = this.getKnowtatorURI(jCas);
+ if (!new File(knowtatorURI).exists()) {
+ LOGGER.fatal("no such Knowtator XML file " + knowtatorURI);
return;
}
@@ -111,7 +119,7 @@ public class SHARPKnowtatorXMLReader ext
KnowtatorXMLParser parser = new KnowtatorXMLParser(this.getAnnotatorNames());
Collection<KnowtatorAnnotation> annotations;
try {
- annotations = parser.parse(knowtatorXML);
+ annotations = parser.parse(knowtatorURI);
} catch (JDOMException e) {
throw new AnalysisEngineProcessException(e);
} catch (IOException e) {
@@ -779,7 +787,7 @@ public class SHARPKnowtatorXMLReader ext
} else if (eventRelationTypes.contains(annotation.type)) {
// store the ALINK information for later, once all annotations are in the CAS
DelayedRelation relation = new DelayedRelation();
- relation.sourceFile = knowtatorXML;
+ relation.sourceFile = knowtatorURI;
relation.annotation = annotation;
relation.source = annotationSlots.remove("Event");
relation.target = annotationSlots.remove("related_to");
@@ -789,7 +797,7 @@ public class SHARPKnowtatorXMLReader ext
} else if (entityRelationTypes.contains(annotation.type)) {
// store the relation information for later, once all annotations are in the CAS
DelayedRelation relation = new DelayedRelation();
- relation.sourceFile = knowtatorXML;
+ relation.sourceFile = knowtatorURI;
relation.annotation = annotation;
relation.source = annotationSlots.remove("Argument_CU");
relation.target = annotationSlots.remove("Related_to_CU");
@@ -802,7 +810,7 @@ public class SHARPKnowtatorXMLReader ext
throw new UnsupportedOperationException(String.format(
"unrecognized type '%s' in %s",
annotation.type,
- knowtatorXML));
+ knowtatorURI));
}
// make sure all slots have been consumed
@@ -818,7 +826,7 @@ public class SHARPKnowtatorXMLReader ext
annotation.type,
entry.getKey(),
remainingSlots,
- knowtatorXML));
+ knowtatorURI));
}
}
}
Modified: incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEKnowtatorXMLReader.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEKnowtatorXMLReader.java?rev=1411634&r1=1411633&r2=1411634&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEKnowtatorXMLReader.java (original)
+++ incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEKnowtatorXMLReader.java Tue Nov 20 12:03:29 2012
@@ -46,10 +46,15 @@ public class THYMEKnowtatorXMLReader ext
THYMEKnowtatorXMLReader.PARAM_KNOWTATOR_XML_DIRECTORY,
knowtatorXMLDirectory);
}
+
+ @Override
+ protected URI getTextURI(JCas jCas) throws AnalysisEngineProcessException {
+ return ViewURIUtil.getURI(jCas);
+ }
@Override
- protected URI getKnowtatorXML(JCas jCas) throws AnalysisEngineProcessException {
- URI uri = ViewURIUtil.getURI(jCas);
+ protected URI getKnowtatorURI(JCas jCas) throws AnalysisEngineProcessException {
+ URI uri = this.getTextURI(jCas);
File file = new File(uri.getPath());
String subDir = file.getParentFile().getName();
Matcher matcher = Pattern.compile("^doc(\\d+)$").matcher(subDir);