You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
list/src/main/java/data/MultipleHMKeys4.java

78 lines
2.2 KiB

package data;
import java.util.ArrayList;
import java.util.Objects;
/*
Created for when words are sorted by multiple keys, i.e. not just lemmas but lemmas and msd simultaneously.
*/
public final class MultipleHMKeys4 implements MultipleHMKeys {
private final String k1, k2, k3, k4;
public MultipleHMKeys4(String k1, String k2, String k3, String k4) {
this.k1 = k1;
this.k2 = k2;
this.k3 = k3;
this.k4 = k4;
}
public String getK1() {
return k1;
}
public String getK2() {
return k2;
}
public String getK3() {
return k3;
}
public String getK4() {
return k4;
}
public ArrayList<MultipleHMKeys> getSplittedMultipleHMKeys(){
ArrayList<MultipleHMKeys> r = new ArrayList<>();
String[] splitedK1 = k1.split("\\s+");
String[] splitedK2 = k2.split("\\s+");
String[] splitedK3 = k3.split("\\s+");
String[] splitedK4 = k4.split("\\s+");
for(int i = 0; i < splitedK1.length; i ++){
// in GOS words and normalized words may not both have specific word due to anon
if(!(i < splitedK2.length && i < splitedK3.length && i < splitedK4.length)){
continue;
}
MultipleHMKeys search = new MultipleHMKeys4(splitedK1[i], splitedK2[i], splitedK3[i], splitedK4[i]);
r.add(search);
}
return r;
}
@Override
public int hashCode() {
return Objects.hash(k1, k2, k3, k4);
}
@Override
public boolean equals(Object obj) {
return (obj instanceof MultipleHMKeys4) && ((MultipleHMKeys4) obj).k1.equals(k1)
&& ((MultipleHMKeys4) obj).k2.equals(k2)
&& ((MultipleHMKeys4) obj).k3.equals(k3)
&& ((MultipleHMKeys4) obj).k4.equals(k4);
}
public MultipleHMKeys[] splitNgramTo1grams(){
String[] k1 = getK1().split(" ");
String[] k2 = getK2().split(" ");
String[] k3 = getK3().split(" ");
String[] k4 = getK4().split(" ");
MultipleHMKeys[] res = new MultipleHMKeys[k1.length];
for(int i = 0; i < k1.length; i++){
res[i] = new MultipleHMKeys4(k1[i], k2[i], k3[i], k4[i]);
}
return res;
}
}