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 2015/03/22 18:47:46 UTC
svn commit: r1668421 - in /uima/ruta/trunk/ruta-core/src/main:
antlr3/org/apache/uima/ruta/parser/RutaParser.g
java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
Author: pkluegl
Date: Sun Mar 22 17:47:45 2015
New Revision: 1668421
URL: http://svn.apache.org/r1668421
Log:
UIMA-3650
- started preparations for creating descriptors without ruta ide
Added:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
Modified:
uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
Modified: uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g?rev=1668421&r1=1668420&r2=1668421&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g (original)
+++ uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g Sun Mar 22 17:47:45 2015
@@ -49,6 +49,7 @@ import org.antlr.runtime.RecognitionExce
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;
+import org.apache.commons.lang3.StringUtils;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
@@ -210,6 +211,7 @@ public void setExternalFactory(RutaExter
return parent.getEnvironment().isVariableOfType(name,type);
}
+ /*
public void addType(RutaBlock parent, String type) {
assert !moduleName.contains(".");
assert !type.contains(".");
@@ -220,7 +222,53 @@ public void setExternalFactory(RutaExter
}
parent.getEnvironment().declareType(resolvedType);
+ if(descInfo!= null) {
+ String descriptionString = null;
+ if(StringUtils.isBlank(namespace)) {
+ descriptionString = "Type defined in " + moduleName;
+ } else {
+ descriptionString = "Type defined in " + parent.getNamespace() + "." + moduleName;
+ }
+ String parentType = "uima.tcas.Annotation";
+
+ descInfo.addType(parent.getNamespace()+"."+type.trim(), descriptionString, parentType);
+ }
}
+ */
+ public void addType(RutaBlock parent, Token nameToken, Token parentTypeToken, List featureTypes,
+ List<Token> featureNames) {
+ String name = nameToken.getText();
+ String parentType = "uima.tcas.Annotation";
+ if(parentTypeToken != null) {
+ parentType = parentTypeToken.getText();
+ }
+ String resolvedType = name;
+ if (!name.contains(".")) {
+ resolvedType = namespace + "." + moduleName + "." + name;
+ }
+ parent.getEnvironment().declareType(resolvedType);
+ if(descInfo != null) {
+ name = parent.getNamespace() + "." + name.trim();
+ String descriptionString = null;
+ if(StringUtils.isBlank(namespace)) {
+ descriptionString = "Type defined in " + moduleName;
+ } else {
+ descriptionString = "Type defined in " + parent.getNamespace() + "." + moduleName;
+ }
+ descInfo.addType(name, descriptionString, parentType);
+ if(featureTypes != null && featureNames != null) {
+ for (int i = 0; i < featureTypes.size(); i++) {
+ Object object = featureTypes.get(i);
+ String ftype = "";
+ if (object instanceof Token) {
+ ftype = ((Token) object).getText();
+ }
+ String fname = featureNames.get(i).getText();
+ descInfo.addFeature(name, fname, fname, ftype);
+ }
+ }
+ }
+ }
public boolean isType(RutaBlock parent, String type) {
return parent.getEnvironment().getType(type) != null || type.equals("Document");
@@ -234,15 +282,27 @@ public void setExternalFactory(RutaExter
public void addImportTypeSystem(RutaBlock parent, String descriptor) {
parent.getEnvironment().addTypeSystem(descriptor);
+ if(descInfo != null) {
+ descInfo.addTypeSystem(descriptor);
+ }
}
public void addImportScript(RutaBlock parent, String namespace) {
parent.getScript().addScript(namespace, null);
+ if(descInfo != null) {
+ descInfo.addScript(namespace);
+ }
}
public void addImportEngine(RutaBlock parent, String namespace) {
parent.getScript().addEngine(namespace, null);
+ if(descInfo != null) {
+ descInfo.addEngine(namespace);
+ }
}
public void addImportUimafitEngine(RutaBlock parent, String namespace) {
parent.getScript().addUimafitEngine(namespace, null);
+ if(descInfo != null) {
+ descInfo.addUimafitEngine(namespace);
+ }
}
/**
@@ -258,6 +318,9 @@ public void setExternalFactory(RutaExter
} else {
parent.getEnvironment().importTypeFromTypeSystem(typesystem, qualifiedType, alias.getText());
}
+ if(descInfo != null) {
+ descInfo.addTypeSystem(typesystem);
+ }
}
/**
@@ -276,6 +339,9 @@ public void setExternalFactory(RutaExter
} else {
env.importPackage(qualifiedPackage, aliasText);
}
+ if(descInfo != null) {
+ descInfo.addTypeSystem(typesystem);
+ }
}
/**
@@ -290,6 +356,9 @@ public void setExternalFactory(RutaExter
String aliasText = alias != null? alias.getText() : null;
env.importAllPackagesFromTypeSystem(typesystem, aliasText);
+ if(descInfo != null) {
+ descInfo.addTypeSystem(typesystem);
+ }
}
protected static final int[] getBounds(Token t) {
@@ -515,10 +584,10 @@ List featureNames = new ArrayList();
DECLARE
//{!isType($blockDeclaration::env, input.LT(1).getText())}?
lazyParent = annotationType?
- id = Identifier {addType($blockDeclaration::env, id.getText());}
+ id = Identifier {addType($blockDeclaration::env, id, lazyParent, null, null);}
(COMMA
//{!isType($blockDeclaration::env, input.LT(1).getText())}?
- id = Identifier {addType($blockDeclaration::env, id.getText());}
+ id = Identifier {addType($blockDeclaration::env, id, lazyParent, null, null);}
)* SEMI
|
DECLARE type = annotationType newName = Identifier
@@ -544,7 +613,9 @@ List featureNames = new ArrayList();
)
fname = Identifier{featureNames.add(fname.getText());})*
RPAREN) SEMI
- {addType($blockDeclaration::env, newName.getText());}
+ {
+ addType($blockDeclaration::env, id, type, featureTypes, featureNames);
+ }
)
;
Added: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java?rev=1668421&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java (added)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/descriptor/RutaDescriptorFactory.java Sun Mar 22 17:47:45 2015
@@ -0,0 +1,63 @@
+/*
+ * 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.descriptor;
+
+import java.io.File;
+
+import org.antlr.runtime.ANTLRFileStream;
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.ruta.RutaModule;
+import org.apache.uima.ruta.parser.RutaLexer;
+import org.apache.uima.ruta.parser.RutaParser;
+
+public class RutaDescriptorFactory {
+
+ public RutaDescriptorFactory() {
+ super();
+ }
+
+ public TypeSystemDescription createTypeSystemDescription(String rules) throws RecognitionException {
+ CharStream st = new ANTLRStringStream(rules);
+ RutaLexer lexer = new RutaLexer(st);
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ RutaParser parser = new RutaParser(tokens);
+ RutaDescriptorInformation descInfo = new RutaDescriptorInformation();
+// parser.setContext(context);
+// parser.setExternalFactory(factory);
+// parser.setResourcePaths(resourcePaths);
+// parser.setResourceManager(resourceManager);
+ parser.setDescriptorInformation(descInfo);
+ parser.file_input("Anonymous");
+// RutaDescriptorBuilder builder = new RutaDescriptorBuilder(defaultTypeSystem, defaultEngine);
+ return null;
+ }
+
+ public AnalysisEngineDescription createAnalysisEngineDescription() {
+ return null;
+ }
+
+
+}
+