On 1/19/2010 14:16, Jérôme Rocheteau wrote:
> Hello everybody,
>
> I'd like to know how to create and set up feature paths and, precisely, I
> would like
> to know how to use the initialize method correctly.
>
> In the following example, I both use the initialize and addfeature methods to
> set up
> feature paths:
>
> private FeaturePath getFeaturePath(JCas cas,Feature feature) {
> FeaturePath path = cas.createFeaturePath();
> path.addFeature(feature);
> return path;
> }
>
> private FeaturePath getFeaturePath(JCas cas,String feature) throws
> CASException {
> FeaturePath path = cas.createFeaturePath();
> path.initialize(feature);
> return path;
> }
I did not try this, but from looking at the code: the
initialize method expects a string representation of a
feature path, e.g., "lemma/pos". You're giving it a
Feature, so Java will invoke to toString() method. This,
for a Feature, returns the fully qualified name of the
feature, in your case "uima.tcas.Annotation:begin".
That's not a valid feature path. You can use Feature.getShortName()
if you want to go this route, or use your first version
(which I assume works fine).
--Thilo
>
> private FeaturePath getFeaturePath(JCas cas,Type type,String feat) {
> Feature feature = type.getFeatureByBaseName(feat);
> String alternative = type.getName() + ":" + feat;
> try {
> return this.getFeaturePath(cas,alternative);
> } catch (CASException e) {
> this.getContext().getLogger().log(Level.SEVERE,e.getMessage());
> return this.getFeaturePath(cas,feature);
> }
> }
>
> However, I get this error message while processing an Analysis Engine that
> calls
> such methods:
>
> "Invalid featurePath syntax for featurePath "uima.tcas.Annotation:begin".
> "begin" is not allowed.
>
> What am I doing wrong with the initialize method?
>
>
> Thank in advance,
> jérôme