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 2013/07/01 14:23:15 UTC

svn commit: r1498407 - in /uima/sandbox/ruta/trunk: ruta-core/src/main/java/org/apache/uima/ruta/engine/ ruta-core/src/main/resources/org/apache/uima/ruta/engine/ ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/wizards/

Author: pkluegl
Date: Mon Jul  1 12:23:15 2013
New Revision: 1498407

URL: http://svn.apache.org/r1498407
Log:
UIMA-2997
- added view copier component (yet deactivated)

Added:
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java
    uima/sandbox/ruta/trunk/ruta-core/src/main/resources/org/apache/uima/ruta/engine/ViewWriter.xml
Modified:
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
    uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java?rev=1498407&r1=1498406&r2=1498407&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/RutaEngine.java Mon Jul  1 12:23:15 2013
@@ -37,7 +37,6 @@ import org.antlr.runtime.ANTLRInputStrea
 import org.antlr.runtime.CharStream;
 import org.antlr.runtime.CommonTokenStream;
 import org.antlr.runtime.RecognitionException;
-import org.apache.uima.UIMAFramework;
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_component.AnalysisComponent;
 import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
@@ -50,12 +49,9 @@ import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.cas.text.AnnotationIndex;
 import org.apache.uima.fit.factory.AnalysisEngineFactory;
-import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceConfigurationException;
 import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceManager;
-import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.ruta.FilterManager;
 import org.apache.uima.ruta.RutaBlock;
 import org.apache.uima.ruta.RutaModule;
@@ -75,7 +71,6 @@ import org.apache.uima.ruta.visitor.Ruta
 import org.apache.uima.ruta.visitor.StatisticsVisitor;
 import org.apache.uima.ruta.visitor.TimeProfilerVisitor;
 import org.apache.uima.util.InvalidXMLException;
-import org.apache.uima.util.XMLInputSource;
 
 public class RutaEngine extends JCasAnnotator_ImplBase {
 

Added: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java?rev=1498407&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java (added)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/ViewWriter.java Mon Jul  1 12:23:15 2013
@@ -0,0 +1,129 @@
+/*
+ * 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.ruta.engine;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.JCasMultiplier_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.AbstractCas;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.CasCopier;
+import org.apache.uima.util.XMLSerializer;
+
+public class ViewWriter extends JCasMultiplier_ImplBase {
+
+  private static final String OUTPUT = "output";
+  private static final String INPUT_VIEW = "inputView";
+  private static final String OUTPUT_VIEW = "outputView";
+  
+  private String outputLocation;
+  private String inputView;
+  private String outputView;
+  private CAS outView;
+
+  @Override
+  public void initialize(UimaContext aContext) throws ResourceInitializationException {
+    super.initialize(aContext);
+    outputLocation = (String) aContext.getConfigParameterValue(OUTPUT);
+    inputView= (String) aContext.getConfigParameterValue(INPUT_VIEW);
+    outputView= (String) aContext.getConfigParameterValue(OUTPUT_VIEW);
+  }
+
+  private static void writeXmi(CAS aCas, File name) throws Exception {
+    FileOutputStream out = null;
+
+    try {
+      // write XMI
+      out = new FileOutputStream(name);
+      XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
+      XMLSerializer xmlSer = new XMLSerializer(out, false);
+      ser.serialize(aCas, xmlSer.getContentHandler());
+    } catch (Exception e) {
+      throw e;
+    } finally {
+      if (out != null) {
+        out.close();
+      }
+    }
+  }
+
+  @Override
+  public void process(JCas jcas) throws AnalysisEngineProcessException {
+    CAS cas = jcas.getCas();
+    Type sdiType = cas.getTypeSystem().getType(RutaEngine.SOURCE_DOCUMENT_INFORMATION);
+
+    String filename = "output.xmi";
+    File file = new File(outputLocation, filename);
+    if (sdiType != null) {
+      FSIterator<AnnotationFS> sdiit = cas.getAnnotationIndex(sdiType).iterator();
+      if (sdiit.isValid()) {
+        AnnotationFS annotationFS = sdiit.get();
+        Feature uriFeature = sdiType.getFeatureByBaseName("uri");
+        String stringValue = annotationFS.getStringValue(uriFeature);
+        File f = new File(stringValue);
+        String name = f.getName();
+        if (!name.endsWith(".xmi")) {
+          name = name + ".xmi";
+        }
+        String parent = f.getParent().endsWith("/") ? f.getParent() : f.getParent() + "/";
+        file = new File(parent + outputLocation, name);
+        file.getParentFile().mkdirs();
+      }
+
+    }
+    CAS inView = cas.getView(inputView);
+    if(outView == null) {
+      outView = getContext().getEmptyCas(CAS.class);
+    }
+    outView.reset();
+    CasCopier cc = new CasCopier(inView, outView);
+    // uncomment for uimaj-2.4.1
+//    cc.copyCasView(inView, outputView, true);
+    try {
+      writeXmi(outView, file);
+    } catch (Exception e) {
+      throw new AnalysisEngineProcessException(e);
+    }
+  }
+  
+  @Override
+  public void collectionProcessComplete() {
+    outView.release();
+    outView = null;
+  }
+  
+  public boolean hasNext() throws AnalysisEngineProcessException {
+    return false;
+  }
+
+  public AbstractCas next() throws AnalysisEngineProcessException {
+    return null;
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-core/src/main/resources/org/apache/uima/ruta/engine/ViewWriter.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/resources/org/apache/uima/ruta/engine/ViewWriter.xml?rev=1498407&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/resources/org/apache/uima/ruta/engine/ViewWriter.xml (added)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/resources/org/apache/uima/ruta/engine/ViewWriter.xml Mon Jul  1 12:23:15 2013
@@ -0,0 +1,68 @@
+<?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.ruta.engine.ViewWriter</annotatorImplementationName>
+  <analysisEngineMetaData>
+    <name>XMLConverter</name>
+    <description/>
+    <version>1.0</version>
+    <vendor/>
+    <configurationParameters>
+      <configurationParameter>
+        <name>outputView</name>
+        <type>String</type>
+        <multiValued>false</multiValued>
+        <mandatory>false</mandatory>
+      </configurationParameter>
+      <configurationParameter>
+        <name>inputView</name>
+        <type>String</type>
+        <multiValued>false</multiValued>
+        <mandatory>false</mandatory>
+      </configurationParameter>
+      <configurationParameter>
+        <name>output</name>
+        <type>String</type>
+        <multiValued>false</multiValued>
+        <mandatory>false</mandatory>
+      </configurationParameter>
+    </configurationParameters>
+    <configurationParameterSettings/>
+    <typeSystemDescription/>
+    <typePriorities/>
+    <fsIndexCollection/>
+    <capabilities>
+      <capability>
+        <inputs/>
+        <outputs/>
+        <languagesSupported/>
+      </capability>
+    </capabilities>
+    <operationalProperties>
+      <modifiesCas>true</modifiesCas>
+      <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+      <outputsNewCASes>true</outputsNewCASes>
+    </operationalProperties>
+  </analysisEngineMetaData>
+  <resourceManagerConfiguration/>
+</analysisEngineDescription>

Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java?rev=1498407&r1=1498406&r2=1498407&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java Mon Jul  1 12:23:15 2013
@@ -41,6 +41,7 @@ import org.eclipse.core.runtime.IProgres
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.dltk.core.DLTKCore;
 import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IScriptProject;
 import org.eclipse.dltk.internal.ui.util.CoreUtility;
 import org.eclipse.dltk.internal.ui.wizards.buildpath.BPListElement;
 import org.eclipse.dltk.ui.DLTKUIPlugin;
@@ -85,7 +86,13 @@ public class RutaProjectCreationWizard e
   }
 
   public void createProject(IProgressMonitor monitor) throws CoreException {
-    IProject project = fSecondPage.getScriptProject().getProject();
+    IScriptProject scriptProject = fSecondPage.getScriptProject();
+    createRutaProject(scriptProject, fSecondPage.getRawBuildPath(), monitor);
+  }
+
+  public static void createRutaProject(IScriptProject scriptProject, IBuildpathEntry[] buildPath,
+          IProgressMonitor monitor) throws CoreException {
+    IProject project = scriptProject.getProject();
     IFolder folder = project.getFolder(RutaProjectUtils.getDefaultInputLocation());
     if (!folder.exists()) {
       CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
@@ -117,24 +124,24 @@ public class RutaProjectCreationWizard e
     }
 
     List<BPListElement> buildpathEntries = new ArrayList<BPListElement>();
-    for (IBuildpathEntry buildpathEntry : fSecondPage.getRawBuildPath()) {
-      BPListElement createFromExisting = BPListElement.createFromExisting(buildpathEntry,
-              fSecondPage.getScriptProject());
-      if (createFromExisting.getBuildpathEntry().getEntryKind() != IBuildpathEntry.BPE_SOURCE) {
-        buildpathEntries.add(createFromExisting);
+    if (buildPath != null) {
+      for (IBuildpathEntry buildpathEntry : buildPath) {
+        BPListElement createFromExisting = BPListElement.createFromExisting(buildpathEntry,
+                scriptProject);
+        if (createFromExisting.getBuildpathEntry().getEntryKind() != IBuildpathEntry.BPE_SOURCE) {
+          buildpathEntries.add(createFromExisting);
+        }
       }
     }
     IBuildpathEntry newSourceEntry = DLTKCore.newSourceEntry(srcFolder.getFullPath());
-    buildpathEntries.add(BPListElement.createFromExisting(newSourceEntry,
-            fSecondPage.getScriptProject()));
+    buildpathEntries.add(BPListElement.createFromExisting(newSourceEntry, scriptProject));
 
-    BuildpathsBlock.flush(buildpathEntries, fSecondPage.getScriptProject(), monitor);
+    BuildpathsBlock.flush(buildpathEntries, scriptProject, monitor);
     copyDescriptors(descFolder);
 
     RutaProjectUtils.addProjectDataPath(project, descFolder);
 
     descFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
-
   }
 
   public static void copyDescriptors(IFolder descFolder) {
@@ -156,7 +163,7 @@ public class RutaProjectCreationWizard e
     copy(utilsDir, "HtmlTypeSystem.xml");
     copy(utilsDir, "HtmlConverter.xml");
     copy(utilsDir, "Cutter.xml");
-//    copy(utilsDir, "ViewWriter.xml");
+    copy(utilsDir, "ViewWriter.xml");
   }
 
   private static void copy(File dir, String fileName) {