-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtag.java
More file actions
57 lines (42 loc) · 1.21 KB
/
tag.java
File metadata and controls
57 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.IOException;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class tag
{
//Include here what words to select...
static String[] select = {"NN","NNS","NP","NPS","NNP"};
public static void main(String[] args) throws IOException, ClassNotFoundException
{
// Initialize the tagger
MaxentTagger tagger = new MaxentTagger("taggers/bidirectional-distsim-wsj-0-18.tagger");
// The input string
String sample = "Which is the highest peak in Europe?";
// The tagged string
String tagged = tagger.tagString(sample);
String[] keywords = new String[10];
//Now select the keywords
String[] all=tagged.split(" ");
int nk=0;
for(int i=0;i<all.length;i++)
{
int pos=all[i].indexOf('/');
String type = all[i].substring(pos+1);
if(isKeyword(type))
keywords[nk++]=all[i].substring(0,pos);
}
// Output the result
System.out.println(tagged);
//for(int i=0;i<all.length;i++)
//System.out.println(all[i]);
for(int i=0;i<keywords.length;i++)
System.out.println(keywords[i]);
}
private static boolean isKeyword(String type)
{
for(int i=0;i<select.length;i++)
{
if(type.equals(select[i]))
return true;
}
return false;
}
}