You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by "Rupert Westenthaler (JIRA)" <ji...@apache.org> on 2012/11/21 13:26:01 UTC

[jira] [Commented] (STANBOL-735) OpenNLP POS Tagger Engine

    [ https://issues.apache.org/jira/browse/STANBOL-735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501912#comment-13501912 ] 

Rupert Westenthaler commented on STANBOL-735:
---------------------------------------------

Documentation for this engine

OpenNLP POS Tagging Engine
==========

POS tagging Engine using the [AnalyzedText](../nlp/analyzedtext) ContentPart based on the [OpenNLP](http://opennlp.apache.org) POS tagging functionality.

## POS Tagging

POS tags are represented by adding _NlpAnnotations#POS_ANNOTATION_'s to the _Tokens_ of the _AnalyzedText_ content part. As the OpenNLP Tokenizer supports multiple Pos tags/probability suggestions the OpenNLP POS Tagging Engine can add multiple POS annotations to an Token.

POS annotations are added by using the key "stanbol.enhancer.nlp.pos" and are represented by the _PosTag_ class. However typical users will rather use the _NlpAnnotations#POS_ANNOTATION_ to access POS annotations of tokens

    :::java
    //The POS tag with the highest probability
    Value<PosTag> posAnnotation = token.getAnnotation(NlpAnnotations.POS_ANNOTATION);
    //Get the list of all POS annotations
    List<Value<PosTag>> posAnnotations = token.getAnnotations(NlpAnnotations.POS_ANNOTATION);

    //Value provides the probability and the PosTag
    double prob = posAnnotation.probability();
    PosTag pos = posAnnotation.value();
    //The string tag as used by the Tokenizer
    String tag = pos.getTag();

    //POS tags can be mapped to LexicalCategories and Pos types
    //so we can check if a Token is a Noun without the need to
    //know the POS tags used by the POS tagger of the current language
    boolean isNoun = pos.hasCategory(LexicalCategory.Noun);
    boolean isProperNoun = pos.hasPos(Pos.ProperNoun);

    //but not all PosTags might be mapped so we should check for
    boolean mapped = pos.isMapped();

The OpenNLP Pos Tagging engine supports mapped PosTags for the following languages

* English: based on the Penn Treebank mappings to the [OLiA Ontology](http://nlp2rdf.lod2.eu/olia/) ([annotation model](http://purl.org/olia/penn.owl), [linking model](http://purl.org/olia/penn-link.rdf))
* German: based on the STTS mapping to the [OLiA Ontology](http://nlp2rdf.lod2.eu/olia/) ([annotation model](http://purl.org/olia/stts.owl), [linking model](http://purl.org/olia/stts-link.rdf))
* Spanish: based on the PAROLE TagSet mapping to the [OLiA Ontology](http://nlp2rdf.lod2.eu/olia/) ([annotation model](http://purl.org/olia/parole_es_cat.owl))
* Danish: mappings for the PAROLE Tagset as described by [this paper](http://korpus.dsl.dk/paroledoc_en.pdf).
* Portuguese: mappings based on the [PALAVRAS tag set](http://beta.visl.sdu.dk/visl/pt/symbolset-floresta.html)
* Dutch: mappings based on the WOTAN Tagset for Dutch as described by _"WOTAN: Een automatische grammatikale tagger voor het Nederlands", doctoral dissertation, Department of language & Speech, Nijmegen University (renamed to Radboud University), december 1994."_. _NOTE_ that this TagSet does NOT distinguish between _ProperNoun_s and _CommonNoun_s.
* Swedish: based on the [Lexical categories in MAMBA](http://w3.msi.vxu.se/users/nivre/research/MAMBAlex.html)

__TODO:__ Currently the Engine is limited to those TagSets as it is not yet possible to extend this by additional one.

## Tokenizing and Sentence Detection Support

The OpenNLP POS Tagging engine implicitly supports tokenizing and sentence detection. That means if the _[AnalyzedText](../nlp/analysedtext)_ is not present or does not contain _Token_s than this engine will use the OpenNLP Tokenizer to tokenize the text. If no language specific OpenNLP tokenizer model is available, than it will use the SIMPLE_TOKENIZER. 

Sentence detection is only done if no _Sentence_s are present in the _AnalyzedText_ AND if an language specific sentence detection model is available.

__NOTE__: Support for Tokenizing and Sentence Detection is not a replacement for explicitly adding an Tokenizing and Sentence Detection Engine to an Enhancement Chain as this Engine does not guarantee that _Token_s or _Sentence_s are added to the _AnalyzedText_ content part. If no POS model is available for a language or a language is not configured to be processed there will be no _Token_s nor _Sentence_s added. Chains the relay on _Token_s and/or _Sentence_s MUST explicitly include a Tokenizing and Sentence detection engine!


## Configuration

_NOTE_ that the OpenNLP POS Tagging engine provides a default service instance (configuration policy is optional). This instance processes all languages where default POS models are provided by the OpenNLP service. This Engine instance uses the name 'opennlp-pos' and has a service ranking of '-100'.

While this engine supports the default configuration including the __name__ _(stanbol.enhancer.engine.name)_ and the __ranking__ _(service.ranking)_ the engine also allows to configure __processed languages__ _(org.apache.stanbol.enhancer.pos.languages)_ and an parameter to specify the name of the POS model used for an language.

__1. Processed Language Configuraiton:__

For the configuration of the processed languages the following syntax is used:

    de
    en
    
This would configure the Engine to only process German and English texts. It is also possible to explicitly exclude languages

    !fr
    !it
    *

This specifies that all Languages other than French and Italien are processed.

Values can be parsed as Array or Vector. This is done by using the ["elem1","elem2",...] syntax as defined by OSGI ".config" files. As fallback also ',' separated Strings are supported. 

The following example shows the two above examples combined to a single configuration.

    org.apache.stanbol.enhancer.pos.languages=["!fr","!it","de","en","*"]

NOTE that the "processed language" configuration only specifies what languages are considered for processing. If "de" is enabled, but there is no POS model available for that language, than German text will still not be processed. However if there is an POS model for "it" but the "processed language" configuration does not include Italian, than Italian text will NOT be processed. 

__2. POS model parameter__

The OpenNLP POS annotation engine supports the 'model' parameter to explicitly parse the name of the POS model used for an language. POS models are loaded via the Stanbol DataFile provider infrastructure. That means that models can be loaded from the {stanbol-working-dir}/stanbol/datafiles folder.

The syntax for parameters is as follows

    {language};{param-name}={param-value}

So to use the "my-de-pos-model.zip" for POS tagging German texts one can use a configuration like follows

    de;model=my-de-pos-model.zip
    *

                
> OpenNLP POS Tagger Engine
> -------------------------
>
>                 Key: STANBOL-735
>                 URL: https://issues.apache.org/jira/browse/STANBOL-735
>             Project: Stanbol
>          Issue Type: Sub-task
>            Reporter: Rupert Westenthaler
>
> EnhancementEngine based on the AnalysedText ContentPart that takes text/plain from a content item and stores an AnalyzedText content part in the content item where each token is assigned its grammar POS tag.
> This EnhancementEngine can consume
> * preexisting Tokens (if someone do not want to use a different Tokenizer as the OpenNLP one)
> * preexisting Sentences (of someone want to use a different Sentence detector as the OpenNLP one)  
> if no tokens/sentences are present the Engine will use the OpenNLP components.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira