Author: pkluegl Date: Fri Apr 26 06:46:34 2013 New Revision: 1476068 URL: http://svn.apache.org/r1476068 Log: UIMA-2834 - added first version of example project for language extensions
Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/marker-file-identifying-eclipse-plugin uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/plugin.xml uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/pom.xml uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleAction.java uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionExtension.java uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionIDEExtension.java uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/resources/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/test/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/test/java/ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/test/resources/ Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/marker-file-identifying-eclipse-plugin URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/marker-file-identifying-eclipse-plugin?rev=1476068&view=auto ============================================================================== (empty) Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/plugin.xml URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/plugin.xml?rev=1476068&view=auto ============================================================================== --- uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/plugin.xml (added) +++ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/plugin.xml Fri Apr 26 06:46:34 2013 @@ -0,0 +1,30 @@ +<?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. +--> + +<plugin> + <extension + point="org.apache.uima.textmarker.ide.actionExtension"> + <action + class="org.apache.uima.textmarker.example.extensions.ExampleActionIDEExtension" + engine="org.apache.uima.textmarker.example.extensions.ExampleActionExtension"> + </action> + </extension> + +</plugin> Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/pom.xml URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/pom.xml?rev=1476068&view=auto ============================================================================== --- uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/pom.xml (added) +++ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/pom.xml Fri Apr 26 06:46:34 2013 @@ -0,0 +1,131 @@ +<?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. +--> + +<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> + <artifactId>textmarker-ep-example-extensions</artifactId> + <version>2.0.1-SNAPSHOT</version> + <name>Example for language extensions</name> + <parent> + <groupId>org.apache.uima</groupId> + <artifactId>textmarker-parent</artifactId> + <version>2.0.1-SNAPSHOT</version> + <relativePath>../textmarker-parent/pom.xml</relativePath> + </parent> + <url>${uimaWebsiteUrl}</url> + <dependencies> + <dependency> + <groupId>org.apache.uima</groupId> + <artifactId>textmarker-core</artifactId> + <version>${project.parent.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.uima</groupId> + <artifactId>textmarker-ep-ide</artifactId> + <version>${project.parent.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.eclipse.dltk</groupId> + <artifactId>core</artifactId> + <version>[3.0.1,5.0.0)</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.antlr</groupId> + <artifactId>antlr</artifactId> + <version>3.1.3</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.eclipse.equinox</groupId> + <artifactId>app</artifactId> + <version>[1.3.0,2.0.0)</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.eclipse.emf.ecore</groupId> + <artifactId>xmi</artifactId> + <version>[2.7.0,3.0.0)</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <!-- don't use artifactId as first part of finalName, follow instead the eclipse convention --> + <finalName>org.apache.uima.textmarker.example.extensions_${parsedVersion.osgiVersion}</finalName> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <executions> + <execution> + <id>default-cli</id> + <configuration> + <excludes> + <exclude>release.properties</exclude> <!-- release generated artifact --> + <exclude>marker-file-identifying-*</exclude> + <exclude>issuesFixed/**</exclude> + </excludes> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <executions> + <execution> + <id>uima-bundle</id> + <configuration> + <instructions> + <_nouses>true</_nouses> + <_exportcontents> + org.apache.uima.textmarker.example.extensions + </_exportcontents> + <Require-Bundle> + org.apache.uima.runtime, + org.apache.uima.textmarker.engine, + org.apache.uima.textmarker.ide + </Require-Bundle> + <Import-Package> + </Import-Package> + <Bundle-SymbolicName>org.apache.uima.textmarker.example.extensions;singleton:=true</Bundle-SymbolicName> + <Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment> + <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> + <Eclipse-ExtensibleAPI>true</Eclipse-ExtensibleAPI> + <!-- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> --> + <Eclipse-BuddyPolicy>registered</Eclipse-BuddyPolicy> + <Eclipse-RegisterBuddy>org.apache.uima.runtime,org.apache.uima.textmarker.engine</Eclipse-RegisterBuddy> + </instructions> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> +</project> \ No newline at end of file Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleAction.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleAction.java?rev=1476068&view=auto ============================================================================== --- uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleAction.java (added) +++ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleAction.java Fri Apr 26 06:46:34 2013 @@ -0,0 +1,86 @@ +/* + * 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.example.extensions; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import org.apache.uima.cas.Type; +import org.apache.uima.cas.TypeSystem; +import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.textmarker.TextMarkerStream; +import org.apache.uima.textmarker.action.AbstractTextMarkerAction; +import org.apache.uima.textmarker.expression.number.NumberExpression; +import org.apache.uima.textmarker.rule.RuleElement; +import org.apache.uima.textmarker.rule.RuleMatch; +import org.apache.uima.textmarker.visitor.InferenceCrowd; + +public class ExampleAction extends AbstractTextMarkerAction { + + private List<NumberExpression> indexExprList; + + public ExampleAction(List<NumberExpression> indexExprList) { + super(); + this.indexExprList = indexExprList; + } + + @Override + public void execute(RuleMatch match, RuleElement element, TextMarkerStream stream, + InferenceCrowd crowd) { + List<Integer> indexes = new ArrayList<Integer>(); + for (NumberExpression each : indexExprList) { + int integerValue = each.getIntegerValue(element.getParent()); + indexes.add(integerValue); + } + List<RuleElement> ruleElements = element.getContainer().getRuleElements(); + for (Integer each : indexes) { + if (each > 0 && each <= ruleElements.size()) { + Type type = getRandomType(stream); + RuleElement ruleElement = ruleElements.get(each-1); + List<AnnotationFS> matchedAnnotationsOf = match + .getMatchedAnnotationsOf(ruleElement, stream); + for (AnnotationFS eachMatched : matchedAnnotationsOf) { + AnnotationFS newAFS = stream.getCas().createAnnotation(type, eachMatched.getBegin(), + eachMatched.getEnd()); + stream.addAnnotation(newAFS, true, match); + } + } + } + } + + private Type getRandomType(TextMarkerStream stream) { + Type annotationType = stream.getCas().getAnnotationType(); + TypeSystem typeSystem = stream.getCas().getTypeSystem(); + List<Type> subsumedTypes = typeSystem.getProperlySubsumedTypes(annotationType); + Random r = new Random(); + int nextInt = r.nextInt(subsumedTypes.size()); + return subsumedTypes.get(nextInt); + } + + public List<NumberExpression> getIndexExprList() { + return indexExprList; + } + + public void setIndexExprList(List<NumberExpression> indexExprList) { + this.indexExprList = indexExprList; + } + +} Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionExtension.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionExtension.java?rev=1476068&view=auto ============================================================================== --- uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionExtension.java (added) +++ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionExtension.java Fri Apr 26 06:46:34 2013 @@ -0,0 +1,76 @@ +/* + * 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.example.extensions; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.uima.textmarker.TextMarkerElement; +import org.apache.uima.textmarker.action.AbstractTextMarkerAction; +import org.apache.uima.textmarker.expression.TextMarkerExpression; +import org.apache.uima.textmarker.expression.number.NumberExpression; +import org.apache.uima.textmarker.extensions.ITextMarkerActionExtension; +import org.apache.uima.textmarker.verbalize.TextMarkerVerbalizer; + +import antlr.ANTLRException; + +public class ExampleActionExtension implements ITextMarkerActionExtension { + + private final String[] knownExtensions = new String[] { "ExampleAction" }; + + private final Class<?>[] extensions = new Class[] { ExampleAction.class }; + + public String verbalize(TextMarkerElement element, TextMarkerVerbalizer verbalizer) { + if (element instanceof ExampleAction) { + return verbalizeName(element) + "(" + + verbalizer.verbalizeExpressionList(((ExampleAction) element).getIndexExprList()) + ")"; + } else { + return "UnknownAction"; + } + } + + public AbstractTextMarkerAction createAction(String name, List<TextMarkerExpression> args) + throws ANTLRException { + List<NumberExpression> arguments = new ArrayList<NumberExpression>(); + if (args != null) { + for (TextMarkerExpression each : args) { + if (each instanceof NumberExpression) { + arguments.add((NumberExpression) each); + } else { + throw new ANTLRException("ExampleAction accepts only NumberExpressions as arguments"); + } + } + } + return new ExampleAction(arguments); + } + + public String verbalizeName(TextMarkerElement element) { + return knownExtensions[0]; + } + + public String[] getKnownExtensions() { + return knownExtensions; + } + + public Class<?>[] extensions() { + return extensions; + } + +} Added: uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionIDEExtension.java URL: http://svn.apache.org/viewvc/uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionIDEExtension.java?rev=1476068&view=auto ============================================================================== --- uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionIDEExtension.java (added) +++ uima/sandbox/textmarker/trunk/example-projects/textmarker-ep-example-extensions/src/main/java/org/apache/uima/textmarker/example/extensions/ExampleActionIDEExtension.java Fri Apr 26 06:46:34 2013 @@ -0,0 +1,21 @@ +package org.apache.uima.textmarker.example.extensions; + +import java.util.List; + +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; +import org.apache.uima.textmarker.ide.core.extensions.IIDEActionExtension; +import org.eclipse.dltk.ast.expressions.Expression; + +public class ExampleActionIDEExtension implements IIDEActionExtension { + private final String[] strings = new String[] {"ExampleAction"}; + + public String[] getKnownExtensions() { + return strings; + } + + public void checkSyntax(Token name, List<Expression> arguments) throws RecognitionException { +// TODO + } + +}