-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnounChecker.java
134 lines (116 loc) · 3.59 KB
/
nounChecker.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
java
import opennlp.tools.postag.POSModel;
import opennlp.tools.postag.POSSample;
import opennlp.tools.postag.POSTaggerME;
import opennlp.tools.tokenize.WhitespaceTokenizer;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import java.util.Scanner;
public class Noun {
static String[] x = new String[1000];
static String initial;
static String tagged;
static ArrayList<String> AlTypes = new ArrayList<>();
static ArrayList<String> nouns = new ArrayList<>();
static ArrayList<String> clean = new ArrayList<>();
static ArrayList<String> clean2 = new ArrayList<>();
static ArrayList<String> lowercase = new ArrayList<>();
static ArrayList<String> ffinal = new ArrayList<>();
public static void main(String[] args) throws IOException {
Scanner xD = new Scanner(System.in);
getString();
typeAssigner(initial);
splitWords(tagged);
nounPicker();
cleaner();
setLowercase();
findDuplicate();
stringPrinter();
int x = xD.nextInt();
}
public static String getString() {
Scanner input = new Scanner(System.in);
System.out.print("Enter new string: ");
initial = input.nextLine();
return initial;
}
public static String typeAssigner(String al) throws IOException {
InputStream inputStream = Noun.class.getResourceAsStream("/en-pos-maxent.bin");
POSModel model = new POSModel(inputStream);
POSTaggerME tagger = new POSTaggerME(model);
WhitespaceTokenizer whitespaceTokenizer = WhitespaceTokenizer.INSTANCE;
String[] tokens = whitespaceTokenizer.tokenize(al);
String[] tags = tagger.tag(tokens);
POSSample sample = new POSSample(tokens, tags);
tagged = sample.toString();
return tagged;
}
public static void splitWords(String f) {
x = f.split(" ");
Collections.addAll(AlTypes, x);
}
public static void nounPicker() {
for (String y : AlTypes
) {
if (y.endsWith("_NNP")) {
nouns.add(y);
}
{
if (y.endsWith("_NN")) {
nouns.add(y);
}
}
}
}
public static void cleaner() {
for (String y : nouns
) {
if (y.endsWith("_NNP")) {
clean.add(y.substring(0, y.length() - 4));
}
{
if (y.endsWith("_NN")) {
clean.add(y.substring(0, y.length() - 3));
}
}
}
for (String a : clean
) {
if (a.endsWith(".")) {
clean2.add(a.substring(0, a.length() - 1));
} else if (a.endsWith(",")) {
clean2.add(a.substring(0, a.length() - 1));
}else {
clean2.add(a);
}
}
}
public static void setLowercase(){
for (String b: clean2
) {
lowercase.add(b.toLowerCase());
}
}
public static void findDuplicate(){
int count = 0;
for (int i = 0; i < lowercase.size(); i++) {
for (int j = 0; j < ffinal.size() ; j++) {
if ((lowercase.get(i).equals(ffinal.get(j)))){
count ++;
}
}
if (count == 0){
ffinal.add(lowercase.get(i));
}
count=0;
}
}
public static void stringPrinter(){
for (String i : ffinal
) {
System.out.println(i);
}
}
}