How to add and access local resources

This tutorial explains how to add and access local resources, based on Tesla's integration of the Stanford Parser.

Step 1
Create a new directory named resources within the component project. Than, copy the required resources into this directory.

Step 2
To access a resource, request a file handle from the super class of your component:

        File configFile = super.getResource("englishFactored.ser.gz", false);

The first parameter specifies a path (relative to directory resources, whereas the second parameter defines if the resource should be unzipped or not.

Step 3
The Stanford Parser can be executed with different language models, thus users should be able to select a language model file. This is a good example for Tesla's enhanced configuration options (see Java Annotations): The string parserSettings is defined as configurable item, such that users can use the Configuration Editor to assign values to it. However, only file names of existing language models are valid entries - this is realized by referencing an custom editor and restriction, and by configuring the editor to only allow the selection of single files which end with the sufix "ser.gz".

    @Configuration(name="Language Configuration", defaultValue="germanFactored.ser.gz", 
                restriction=ServerResourcesChoice.class, editorConfiguration={"single", "ser.gz"}, evaluateOnServer=true,
                description="The language file the parser will use.")
    private String parserSettings = "germanFactored.ser.gz";
Step 4
Yes, this was complicated, but, you've just seen the most complicated use case of the - annotation in Tesla. Plus, the results are as expected: