You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2012/08/08 17:31:42 UTC

svn commit: r1370811 - in /uima/sandbox/trunk/TextMarker: uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/ uimaj-textmarker/src/main/java/org/apache/uima/textmarker/engine/ uimaj-textmarker/src/main/resources/org/apache/...

Author: pkluegl
Date: Wed Aug  8 15:31:42 2012
New Revision: 1370811

URL: http://svn.apache.org/viewvc?rev=1370811&view=rev
Log:
UIMA-2452
- added PlainTextAnnotator for lines and paragraphs

Added:
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/engine/PlainTextAnnotator.java
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextAnnotator.xml
    uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextTypeSystem.xml
Modified:
    uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java

Modified: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java?rev=1370811&r1=1370810&r2=1370811&view=diff
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java (original)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/ui/wizards/TextMarkerProjectCreationWizard.java Wed Aug  8 15:31:42 2012
@@ -51,7 +51,6 @@ import org.eclipse.ui.wizards.newresourc
 
 public class TextMarkerProjectCreationWizard extends ProjectWizard {
 
- 
   public static final String ID_WIZARD = "org.apache.uima.textmarker.ide.ui.wizards.TextMarkerProjectWizard"; //$NON-NLS-1$
 
   private ProjectWizardFirstPage fFirstPage;
@@ -66,7 +65,6 @@ public class TextMarkerProjectCreationWi
     setWindowTitle(TextMarkerWizardMessages.ProjectCreationWizard_title);
   }
 
-  
   @Override
   public void addPages() {
     super.addPages();
@@ -81,7 +79,7 @@ public class TextMarkerProjectCreationWi
 
   @Override
   protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
-super.finishPage(monitor);
+    super.finishPage(monitor);
     createProject(monitor);
   }
 
@@ -133,7 +131,7 @@ super.finishPage(monitor);
     copyDescriptors(descFolder);
 
     TextMarkerProjectUtils.addProjectDataPath(project, descFolder);
-    
+
     descFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
 
   }
@@ -187,6 +185,16 @@ super.finishPage(monitor);
       if (in != null && out != null) {
         copy(in, out);
       }
+      in = TextMarkerEngine.class.getResourceAsStream("PlainTextAnnotator.xml");
+      out = new FileOutputStream(new File(utilsDir, "PlainTextAnnotator.xml"));
+      if (in != null && out != null) {
+        copy(in, out);
+      }
+      in = TextMarkerEngine.class.getResourceAsStream("PlainTextTypeSystem.xml");
+      out = new FileOutputStream(new File(utilsDir, "PlainTextTypeSystem.xml"));
+      if (in != null && out != null) {
+        copy(in, out);
+      }
 
     } catch (Exception e) {
       e.printStackTrace();

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/engine/PlainTextAnnotator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/engine/PlainTextAnnotator.java?rev=1370811&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/engine/PlainTextAnnotator.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/engine/PlainTextAnnotator.java Wed Aug  8 15:31:42 2012
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.engine;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URL;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.XMLInputSource;
+
+public class PlainTextAnnotator extends JCasAnnotator_ImplBase {
+
+  public static final String TYPE_LINE = "org.apache.uima.textmarker.type.Line";
+
+  public static final String TYPE_WSLINE = "org.apache.uima.textmarker.type.WSLine";
+
+  public static final String TYPE_PARAGRAPH = "org.apache.uima.textmarker.type.Paragraph";
+
+  @Override
+  public void process(JCas jcas) throws AnalysisEngineProcessException {
+    CAS cas = jcas.getCas();
+    String documentText = cas.getDocumentText();
+    BufferedReader br = new BufferedReader(new StringReader(documentText));
+    Type lineType = cas.getTypeSystem().getType(TYPE_LINE);
+    Type wsLineType = cas.getTypeSystem().getType(TYPE_WSLINE);
+    Type paragraphType = cas.getTypeSystem().getType(TYPE_PARAGRAPH);
+
+    int offsetTillNow = 0;
+    int paragraphBegin = -1;
+    int lastLineEnd = 0;
+
+    boolean lastWasEmpty = true;
+    String eachLine = null;
+    try {
+      while ((eachLine = br.readLine()) != null) {
+        boolean wsLine = "".equals(eachLine.trim());
+        boolean emptyLine = "".equals(eachLine);
+        int offsetAfterLine = offsetTillNow + eachLine.length();
+        int nlLength = 1;
+        String substring = documentText.substring(offsetAfterLine, offsetAfterLine + 2);
+        if (substring.equals("\r\n")) {
+          nlLength = 2;
+        }
+
+        if (lastWasEmpty && !wsLine) {
+          paragraphBegin = offsetTillNow;
+        }
+
+        if (wsLine && !emptyLine) {
+          AnnotationFS newWSLineFS = cas.createAnnotation(wsLineType, offsetTillNow, offsetTillNow
+                  + eachLine.length());
+          cas.addFsToIndexes(newWSLineFS);
+        } else if (!emptyLine) {
+          AnnotationFS newLineFS = cas.createAnnotation(lineType, offsetTillNow, offsetTillNow
+                  + eachLine.length());
+          cas.addFsToIndexes(newLineFS);
+
+          lastWasEmpty = false;
+          lastLineEnd = offsetTillNow + eachLine.length();
+        }
+        if (wsLine && !lastWasEmpty && lastLineEnd != 0) {
+          AnnotationFS newParaFS = cas.createAnnotation(paragraphType, paragraphBegin, lastLineEnd);
+          cas.addFsToIndexes(newParaFS);
+        }
+        if(wsLine) {
+          lastWasEmpty = true;
+        }
+        offsetTillNow = offsetTillNow + eachLine.length() + nlLength;
+      }
+    } catch (IOException e) {
+      throw new AnalysisEngineProcessException(e);
+    }
+
+  }
+
+  public static void main(String[] args) throws Exception {
+    URL url = TextMarkerEngine.class.getClassLoader().getResource("PlainTextAnnotator.xml");
+    if (url == null) {
+      url = PlainTextAnnotator.class.getClassLoader().getResource(
+              "org/apache/uima/textmarker/engine/PlainTextAnnotator.xml");
+    }
+    XMLInputSource in = new XMLInputSource(url);
+    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
+    CAS cas = ae.newCAS();
+    cas.setDocumentText(FileUtils.file2String(new File(
+            "D:/work/workspace-textmarker/Test/input/list1.txt"), "UTF-8"));
+    ae.process(cas);
+    AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
+    for (AnnotationFS annotationFS : annotationIndex) {
+      System.out.println(annotationFS.getType().getShortName() + " :  "
+              + annotationFS.getCoveredText());
+    }
+  }
+
+}

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextAnnotator.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextAnnotator.xml?rev=1370811&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextAnnotator.xml (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextAnnotator.xml Wed Aug  8 15:31:42 2012
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
+  <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+  <primitive>true</primitive>
+  <annotatorImplementationName>org.apache.uima.textmarker.engine.PlainTextAnnotator</annotatorImplementationName>
+  <analysisEngineMetaData>
+    <name>PlainTextAnnotator</name>
+    <description/>
+    <version>1.0</version>
+    <vendor/>
+    <configurationParameters/>
+    <configurationParameterSettings/>
+    <typeSystemDescription>
+      <imports>
+        <import location="PlainTextTypeSystem.xml"/>
+      </imports>
+    </typeSystemDescription>
+    <typePriorities/>
+    <fsIndexCollection/>
+    <capabilities>
+      <capability>
+        <inputs/>
+        <outputs/>
+        <languagesSupported/>
+      </capability>
+    </capabilities>
+    <operationalProperties>
+      <modifiesCas>true</modifiesCas>
+      <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+      <outputsNewCASes>false</outputsNewCASes>
+    </operationalProperties>
+  </analysisEngineMetaData>
+  <resourceManagerConfiguration/>
+</analysisEngineDescription>

Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextTypeSystem.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextTypeSystem.xml?rev=1370811&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextTypeSystem.xml (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/resources/org/apache/uima/textmarker/engine/PlainTextTypeSystem.xml Wed Aug  8 15:31:42 2012
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+  <name>PlainTextTypeSystem</name>
+  <description/>
+  <version>1.0</version>
+  <vendor/>
+  <types>
+    <typeDescription>
+      <name>org.apache.uima.textmarker.type.Line</name>
+      <description/>
+      <supertypeName>org.apache.uima.textmarker.type.AnyLine</supertypeName>
+    </typeDescription>
+    <typeDescription>
+      <name>org.apache.uima.textmarker.type.Paragraph</name>
+      <description/>
+      <supertypeName>uima.tcas.Annotation</supertypeName>
+    </typeDescription>
+    <typeDescription>
+      <name>org.apache.uima.textmarker.type.WSLine</name>
+      <description/>
+      <supertypeName>org.apache.uima.textmarker.type.AnyLine</supertypeName>
+    </typeDescription>
+    <typeDescription>
+      <name>org.apache.uima.textmarker.type.AnyLine</name>
+      <description/>
+      <supertypeName>uima.tcas.Annotation</supertypeName>
+    </typeDescription>
+  </types>
+</typeSystemDescription>