Skip to content
Permalink
3b99e145f5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
87 lines (75 sloc) 2.28 KB
package tool;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import activity.extraction.HelperForOpenIE4Activities;
public class NormalizationText {
public static String normString(String s){
if (s == null) s = "";
return s.replaceAll("[^0-9a-zA-Z ,-.\\_%/+']+", " ")
.replaceAll("'", "")
.replaceAll("\\s+", " ")
.replaceAll(" ,", ",")
.trim().toLowerCase();
}
public static ArrayList<String> normString(ArrayList<String> s){
ArrayList<String> result = new ArrayList<>();
for (int i=0; i<s.size(); i++){
result.add(normString(s.get(i)));
}
return result;
}
public static List<String> normList(List<String> l) throws SQLException, IOException{
List<String> result = new ArrayList<>();
for (int i=0; i<l.size(); i++){
String headword = HelperForOpenIE4Activities.headWord(l.get(i));
headword = headword.contains(" ")?headword.substring(headword.lastIndexOf(" ") + 1):headword;
headword = headword.replaceAll("[,.]", "");
if (!HelperForOpenIE4Activities.STOPWORDS.contains(headword))
result.add(headword);
}
return result;
}
public static List<String> removeStopwordInString(String s) throws SQLException, IOException{
List<String> result = new ArrayList<>();
String[] l = s.split(" ");
for (int i=0; i<l.length; i++){
if (!HelperForOpenIE4Activities.STOPWORDS.contains(l[i]))
result.add(l[i]);
}
return result;
}
public static String listToPhrase(List<String> list){
String res = "";
if (list.size() > 0 && list.get(0).length() > 0){
for (String t:list){
res += t + "_";
}
res = res.substring(0, res.lastIndexOf("_") - 1);
}
return res;
}
public static String arrayToString(double[] vector){
String res = "";
if (vector.length == 1){
return Double.toString(vector[0]);
}else if (vector.length > 1){
for (int i=0; i<vector.length - 1; i++)
res += Double.toString(vector[i]) + " ";
res += Double.toString(vector[vector.length - 1]);
}
return res;
}
public static List<Integer> stringToListInt(String s){
List<Integer> res = new ArrayList<>();
if (!s.contains(";"))
res.add(Integer.parseInt(s));
else{
String [] tmp = s.split(";");
for (String ss: tmp)
res.add(Integer.parseInt(ss));
}
return res;
}
}