Problems loading Ruta TYPESYSTEM - uima

I'm having trouble importing a typesystem into Ruta. I have two projects in my workspace:
UIMA project located ./workspace/UIMA_NLP/
Ruta project located at ./workspace/RUTA_CLARIFY/
I'm trying to load the Type System Definition file: ./workspace/UIMA_NLP/descriptors/type_system/nlpTypes.xml created in the UIMA project into the Ruta script.
I've been able to do this successfully if I copy the Type System Definition into the Ruta project into ./workspace/RUTA_CLARIFY/descriptor/nlpTypes.xml and loading it in the Ruta script with the following:
TYPESYSTEM nlpTypes;
However, when trying to import directly from the UIMA_NLP project I get 'error nlpTypes not found' in the editor. I've tried adding the fully qualified directory of the Type System Descriptor to the descriptorPaths field in the generated ruta engine without any success.
I've tried the following types system imports in script after adding the path to the descriptor paths:
TYPESYSTEM type_system.nlpTypes;
TYPESYSTEM descriptors.type_system.nlpTypes;
TYPESYSTEM UIMA_NLP.descriptors.type_system.nlpTypes;
What is strange is that I can add the nlpTypes.xml Type System Descriptor in the Type System generated by the Ruta script using the Imported Types and Import By Location and the types defined by the imported nlpTypes.xml appear in the Types. I can also type them in the editor when using auto-complete and the types appear. However, I will still get an error in the editor that 'Type "typename" is not defined in this script/block' even after using the auto-complete to complete the type name. Because of this I suspect I am not using the TYPESYSTEM import correctly for this case.
Am I using the TYPESYSTEM import incorrectly? Or is the only way to use my predefined Type System Descriptor to copy it to the Ruta project?

Adding the absolute path to the folder of the type system to the descriptiorPaths configuration parameter of your analysis engine descriptor should work. However, in which xml descriptor did you add it? If it is the generated descriptor of your script, then the modification will be overwritten by the workbench. You need to add the additional path to the template descriptor BasicEngine.xml of the project.
If the descriptorPath contains the paths to the descriptors folder of the other project, then the correct import would read: TYPESYSTEM type_system.nlpTypes;
Normally, you would reference the UIMA project from the Ruta project: Right-click on the Ruta project->Properties->Project References->Check the UIMA project
The default folders of referenced projects are automatically included in the descriptorPaths when the analysis engine descriptor is built by the workbench. In case of UIMA Pear projects, this would be the desc folder. For Java project this would be the output folder, e.g., bin or target/classes.
The strange error you report is really strange. Sounds like a problem of the project setup or descriptors that are not up-to-date. Try to clean the project: Menu->Project->Clean...
The error is maybe false positive due to the project setup. Can you launch the script and get results in the output folder?
I personally recommend using simple Ruta projects only for prototyping. For serious rule projects, especially if there are dependencies to other projects, I'd rather recommend a maven-built project. There is also an archetype for ruta projects in order to ease the setup.
DISCLAIMER: I am a developer of UIMA Ruta

Related

Cannot run UIMA Ruta programs (imports not working?)

I am completely new to Ruta (and to Java).
I installed Eclipse, Maven plugin and Uima Ruta on my computer. I followed the instructions from the UIMA Ruta Guide and Reference. Eclipse shows I have got UIMA Runtime 2.10.2, UIMA Tools 2.10.2, UIMA Ruta Workbench 2.6.1 and UIMA-AS Deployment Descriptor Editor 2.10.3.
But now it turns out that I cannot write (well, compile/run) a single most simple program using Ruta because something is wrong with the imports.
When I write "PACKAGE uima.ruta.example", a red circle appears saying "The package declaration does not match the project structure" -- even if there is no other line in my program.
When I try to compile and run a simple program on an input file (right click on file > UIMA Ruta > Quick Ruta), nothing happens.
I suppose some important files simply haven't been downloaded onto my computer. When I am exploring the directory where I (think I) installed everything, I see there are loads of different "uima" amd "uimaj" packages in there, but I cannot find any packages called 'ruta' or 'ruta.example' or so.
What should I do? Where can I get the 'ruta' library? Does the 'ruta.example' library really exist or is it used in the book just as an example?
(Actually I would also be happy to receive an answer to the question "Why in God's name should I download an environment, install a plugin for it, install a subplugin for it, create a project for it and adjust its settings before writing some programs, instead of just installing and/or compiling some single stuff and just running my program with it in the command line?", but since such a way has not appeared yet officially (has it?), I suppose there should be some serious reasons for that.)
If you use a declaration like PACKAGE uima.ruta.example; it's also required that you put that file in the matching package (directory). So, if your Ruta file names MyExample.ruta it should be located in script/uima/ruta/example/MyExample.ruta. If the Ruta workbench is installed correctly, and you create a default UIMA Ruta project, then it's possible to execute the Ruta file via the file context menu. No additional resources have to be downloaded.
Don't forget to add example input files into the "input" directory. These will be processed and the result will be placed in the "output" directory.
If you are using the Ruta library in Maven project (In a custom project other then running it through the Ruta workbench of Eclipse) you have to add Ruta as dependency in the pom.xml. All transitive dependencies will be downloaded by the Maven system.
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>ruta-core</artifactId>
<version>2.6.1</version>
</dependency>

Apache UIMA Ruta Workbench with custom ruta-core

In our corpus we often find and need to parse data that is alpha-numeric as a single token (for example file hashes, email addresses, etc.) We have created our own ruta-core version by re-working the JFlex definition. Is there a way we can still work with this new version of ruta-core in Workbench?
If you use simple Ruta projects, you would need to replace the ruta.engine plugin with a different jar containing your ruta-core version. The clean way would be to build a complete update site with your version.
You could maybe also set your ruta-core jar in the classpath of your ruta launch configurations.
If you use maven-based projects, you can set the dependency to your version of ruta-core, which should then be used in the launch delegate.
For your use case, I would not use your own version of ruta-core at all. You could simply write your own version of the TokenLexer, as you probably did. Then, you can configure the utilized TokenLexer in the RutaEngine as there is a configuration parameter for setting it. Thus, there is already some functionality to customize the JFlex definition without building your own ruta-core.
DISCLAIMER: I am a developer of UIMA Ruta

Xtext cross-reference across all files in project

I am making a very simple DSL with xtext. A project will contain files that either define a message name, or reference to one. I have included a simplified example:
Grammar:
Model:
statements+=(MessageDefinition | MessageUsage)*;
MessageDefinition:
'[MESSAGE_DEF]' name=ID;
MessageUsage:
'[MESSAGE_USAGE]' usage=[MessageDefinition];
File1.ex:
[MESSAGE_DEF] EXAMPLE_1
[MESSAGE_DEF] EXAMPLE_2
[MESSAGE_USAGE] EXAMPLE_1
File2.ex:
[MESSAGE_USAGE] EXAMPLE_2
In this example the cross-reference from EXAMPLE_1 works such that "Open Declaration" on the usage takes me to the definition. However, the cross-reference on EXAMPLE_2 does not work. I think the default scoping rules prevents different files from sharing references.
What do i need to add so that all the files in a project share the same global scope for cross-references?
Additional information:
The option "Build Automatically" is enabled in the runtime project.
The .project file includes a buildCommand for xtextBuilder and a
nature for xtextNature.
I am only attempting to use the IDE
cross-referencing functionality, there is no generation of code.
All of the files in the runtime project exist in the same folder.
The project was created using "Xtext Project" in the standard wizard, I have only edited the grammar from the pre-generated code, everything else is as-per the defaults. I thought I would need to add some custom scoping behaviour/rules to load all files into the global scope, but I am not sure how this is supposed to be done?
it will work fine with your grammar and scoping if you
have build automatically enabled in your runtime workspace
the project you model in has xtext nature and xtext builder enabled (right-click -> configure -> ...)
if it is a java project model files have to reside in a source folder or a package within the source folder

UIMA Ruta Workbench picks up an incorrect descriptor path

I am new to UIMA Ruta. I try to run the Main.ruta in the ExampleProject came with Ruta 2.1.0 source release using Eclipse 3.7 according to the instruction. It seems the Ruta workbench picks up an incorrect descritor path. I tried to set new Arguments in the "Run Configurations". It doesn't work.
Due to some restriction at work, The UIMA Ruta plugins were installed manaully.
Please help. Thank you!
An error because of incorrect descriptor paths indicates that the plugin are correctly installed, but the descriptors themselves are not updated.
The descriptors use some absolute paths in their parameter configuration. Try to build the project twice in order to regenerate all descriptors, e.g, with Menu->Project->Clean. Then investigate the descriptor ExampleProject/descriptor/uima/ruta/example/MainEngine.xml and check if the absolute paths are correct (pointing to your workspace project), especially the parameter scriptPaths.
Thanks Peter. The problem truns out that Ruta workbench can't handle spaces in descriptor paths. I fixed the space problem and the rebuilt the project. Now it works.

How do I get the Jython PythonPath to reliably include java class paths?

Question
Is there a way to reliably ensure that both the python source paths and compiled java class paths are added to the Jython PythonPath when running unit tests under eclipse?
If not, is there a better workaround than adding absolute paths to the PyDev PythonPath, External Libraries list?
Background
I have been having a strange problem with running Jython unit tests on a Jython class which inherits from a Java class.
We have an eclipse RCP application with a structure (simplified) like this:
Config project (Pydev nature only)
scripts
src
classes.py
test
classesTest.py
Core project (Both Java & Pydev natures)
scripts
src
baseClass.java
classes
baseClass.java
Library project (Both Java & Pydev natues, but no Jython scripts)
src
interface.java
classes
interface.class
In classes.py I import baseClass, which implements an interface defined in interface.java. I then create a Jython class which inherits from baseClass.
In my classesTest.py, I import classes and define the unit tests.
The problems come when I try to run the unit tests using "Project explorer > classesTest.py > Run as > Jython unit-test":
Sometimes it is unable to find the baseClass (I think it fails with an ImportError, but I can't reproduce this right now).
At other times it finds the baseClass, but then can't find the interface, so it fails with a java.lang.NoClassDefFoundError.
If I pprint the sys.path at the start of the test module, then I can see that:
While core/scripts is on the python path, neither core/classes nor library/classes are on the path.
Both core/scripts and core/classes are on the python path, but library/classes still is not.
Sometimes, very rarely, both classes paths are added to the python path and the unit tests work fine, without the workaround below. Unfortunately, I haven't worked out how to reproduce this and can see no difference in the files in the source tree between it working and it not working.
Current Workaround
My current workaround is to explicitly add in "External Libraries" for library/classes and core/classes explicitly. Unfortunately it appears that these have to be absolute paths, which means I have to set them differently for every trunk, branch or computer that I use. As such, I don't want to commit these into revision control and it is a pain having to set them up every time.
Notes
Note that the Config project only references the core project, but referencing the library project explicitly makes no difference to the class path.
Also, while trying to find a reliable method to reproduce this problem, I had other libraries inexplicably disappear from the python path and then just as mysteriously reappear, the most recent example being Mock!
Update
I haven't seen this problem recently (currently using Eclipse 3.7.1 & PyDev 2.2.2) so it may have been an aberration with the combination of Eclipse/PyDev I was using at the time.
For a java project, you have to explicitly add the folder with the .class files to the PYTHONPATH.
The recommended organization would be:
java_project/bin <- this folder should be set as a source folder within PyDev (to be added to the PYTHONPATH).
java_project/src <- this folder should be added to the jdt classpath, but should not have any reference in PyDev
python_project/src <- this folder should be set as a source folder within PyDev (to be added to the PYTHONPATH).
And the python_project should have a reference to the java_project.
See the last part of http://pydev.org/manual_101_project_conf2.html as a reference.
I had a similar problem. Recently resolved by accordingly modifying the python.path field in the Jython registry file.
It looks like the Pydev plugin cannot modify the sys.path to be able to import the Python module from a Java project in Eclipse.
More details at Adding in a python module to the sys.path for a Java project in pydev, Eclipse