package se.lth.cs.nlp.opinions; import java.util.ArrayList; import java.util.Arrays; import se.lth.cs.nlp.nlputils.ml_long.*; public class Sentence { public int[][] features; public Sentence(ArrayList sen, SymbolEncoder enc) { if(sen.size() == 0) throw new IllegalArgumentException("empty"); int n = sen.get(0).length - 1; if(n <= 0) throw new RuntimeException("no columns"); features = new int[sen.size()][n]; for(int i = 0; i < sen.size(); i++) { String[] ss = sen.get(i); if(ss.length != n + 1) { for(String[] xx: sen) System.err.println(Arrays.toString(xx)); throw new IllegalArgumentException("illegal columns"); } for(int j = 0; j < n; j++) features[i][j] = enc.encode(ss[j]); } DEBUG_WORD_ENC = enc; /*System.out.println(""); for(String[] ss: sen) System.out.println(Arrays.toString(ss)); System.out.println("");*/ } static SymbolEncoder DEBUG_WORD_ENC; public String toString() { StringBuilder sb = new StringBuilder(); sb.append("["); for(int i = 0; i < features.length; i++) { if(i > 0) sb.append(", "); sb.append(features[i][0]); sb.append(":"); sb.append(DEBUG_WORD_ENC.decode(features[i][0])); //sb.append("->{"); /*for(int j = 0; j < ranges[i].length; j++) { if(j > 0) sb.append(","); sb.append(DEBUG_LABEL_ENC.decode(ranges[i][j])); }*/ //sb.append("}"); } sb.append("]"); return sb.toString(); } }