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++) { 
    newTags[i] = tags[i]; 
} 
newTags[tags.length] = "newTag"; 
oldTags = tagDictionary.put("force", newTags);

If we redisplay the current tags, as shown here, we can see that the old tags have been retained and the new one has been added:

 /NN/VBP/VB/newTag  
When adding tags, be careful to assign the tags in the proper order, as it will influence which tag is assigned.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset