Java Reference
In-Depth Information
/NN/VBP/VB
This means that the word "force" can be interpreted in three different ways.
Changing a word's tags
The MutableTagDictionary interface's put method allows us to add tags to a
word. The method has two arguments: the word, and its new tags. The method returns an
array containing the previous tags.
In the following example, we replace the old tags with a new tag. The old tags are then
displayed.
String oldTags[] = tagDictionary.put("force", "newTag");
for (String tag : oldTags) {
System.out.print("/" + tag);
}
System.out.println();
The following output lists the old tags for the word.
/NN/VBP/VB
These tags have been replaced by the new tag as demonstrated here where the current tags
are displayed:
tags = tagDictionary.getTags("force");
for (String tag : tags) {
System.out.print("/" + tag);
}
System.out.println();
All we get is the following:
/newTag
To retain the old tags we will need to create an array of strings to hold the old and the new
tags and then use the array as the second argument of the put method as shown here:
String newTags[] = new String[tags.length+1];
for (int i=0; i<tags.length; i++) {
Search WWH ::




Custom Search