public static void main(String[] args) { TwoDimensionalCounter<String, String> cc = new TwoDimensionalCounter<>(); cc.setCount("a", "c", 1.0); cc.setCount("b", "c", 1.0); cc.setCount("a", "d", 1.0); cc.setCount("a", "d", -1.0); cc.setCount("b", "d", 1.0); System.out.println(cc); cc.incrementCount("b", "d", 1.0); System.out.println(cc); TwoDimensionalCounter<String, String> cc2 = TwoDimensionalCounter.reverseIndexOrder(cc); System.out.println(cc2); }
public static <T1, T2> void loadInto2DCounter(String filename, Class<T1> t1, Class<T2> t2, TwoDimensionalCounter<T1, T2> tdc) throws RuntimeException { try { Constructor<T1> m1 = t1.getConstructor(String.class); Constructor<T2> m2 = t2.getConstructor(String.class); BufferedReader in = IOUtils.getBufferedFileReader(filename);// new // BufferedReader(new // FileReader(filename)); for (String line; (line = in.readLine()) != null;) { String[] tuple = line.trim().split("\t"); String outer = tuple[0]; String inner = tuple[1]; String valStr = tuple[2]; tdc.setCount(m1.newInstance(outer.trim()), m2.newInstance(inner.trim()), Double.parseDouble(valStr.trim())); } in.close(); } catch (Exception e) { throw new RuntimeException(e); } }
private void loadMWMap(String filename) { mwCounter = new TwoDimensionalCounter<>(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)), "UTF-8")); int nLines = 0; for(String line; (line = br.readLine()) != null; nLines++) { String[] toks = line.split("\t"); assert toks.length == 3; mwCounter.setCount(toks[0].trim(), toks[1].trim(), Double.parseDouble(toks[2].trim())); } br.close(); System.err.printf("%s: Loaded %d lines from %s into MWE counter%n", this.getClass().getName(),nLines,filename); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
/** * Produces a new ConditionalCounter. * * @return a new ConditionalCounter, where order of indices is reversed */ @SuppressWarnings( { "unchecked" }) public static <K1, K2> TwoDimensionalCounter<K2, K1> reverseIndexOrder(TwoDimensionalCounter<K1, K2> cc) { // they typing on the outerMF is violated a bit, but it'll work.... TwoDimensionalCounter<K2, K1> result = new TwoDimensionalCounter<>((MapFactory) cc.outerMF, (MapFactory) cc.innerMF); for (K1 key1 : cc.firstKeySet()) { ClassicCounter<K2> c = cc.getCounter(key1); for (K2 key2 : c.keySet()) { double count = c.getCount(key2); result.setCount(key2, key1, count); } } return result; }
if (path != null) { int dist = path.size(); nodeDists.setCount(node1, node2, dist);
public static void main(String[] args) { TwoDimensionalCounter<String, String> cc = new TwoDimensionalCounter<String, String>(); cc.setCount("a", "c", 1.0); cc.setCount("b", "c", 1.0); cc.setCount("a", "d", 1.0); cc.setCount("a", "d", -1.0); cc.setCount("b", "d", 1.0); System.out.println(cc); cc.incrementCount("b", "d", 1.0); System.out.println(cc); TwoDimensionalCounter<String, String> cc2 = TwoDimensionalCounter.reverseIndexOrder(cc); System.out.println(cc2); }
public static void main(String[] args) { TwoDimensionalCounter<String, String> cc = new TwoDimensionalCounter<>(); cc.setCount("a", "c", 1.0); cc.setCount("b", "c", 1.0); cc.setCount("a", "d", 1.0); cc.setCount("a", "d", -1.0); cc.setCount("b", "d", 1.0); System.out.println(cc); cc.incrementCount("b", "d", 1.0); System.out.println(cc); TwoDimensionalCounter<String, String> cc2 = TwoDimensionalCounter.reverseIndexOrder(cc); System.out.println(cc2); }
public static void main(String[] args) { TwoDimensionalCounter<String, String> cc = new TwoDimensionalCounter<>(); cc.setCount("a", "c", 1.0); cc.setCount("b", "c", 1.0); cc.setCount("a", "d", 1.0); cc.setCount("a", "d", -1.0); cc.setCount("b", "d", 1.0); System.out.println(cc); cc.incrementCount("b", "d", 1.0); System.out.println(cc); TwoDimensionalCounter<String, String> cc2 = TwoDimensionalCounter.reverseIndexOrder(cc); System.out.println(cc2); }
public static void main(String[] args) { TwoDimensionalCounter<String, String> cc = new TwoDimensionalCounter<String, String>(); cc.setCount("a", "c", 1.0); cc.setCount("b", "c", 1.0); cc.setCount("a", "d", 1.0); cc.setCount("a", "d", -1.0); cc.setCount("b", "d", 1.0); System.out.println(cc); cc.incrementCount("b", "d", 1.0); System.out.println(cc); TwoDimensionalCounter<String, String> cc2 = TwoDimensionalCounter.reverseIndexOrder(cc); System.out.println(cc2); }
public static <T1, T2> void loadInto2DCounter(String filename, Class<T1> t1, Class<T2> t2, TwoDimensionalCounter<T1, T2> tdc) throws RuntimeException { try { Constructor<T1> m1 = t1.getConstructor(String.class); Constructor<T2> m2 = t2.getConstructor(String.class); BufferedReader in = IOUtils.getBufferedFileReader(filename);// new // BufferedReader(new // FileReader(filename)); for (String line; (line = in.readLine()) != null;) { String[] tuple = line.trim().split("\t"); String outer = tuple[0]; String inner = tuple[1]; String valStr = tuple[2]; tdc.setCount(m1.newInstance(outer.trim()), m2.newInstance(inner.trim()), Double.parseDouble(valStr.trim())); } in.close(); } catch (Exception e) { throw new RuntimeException(e); } }
public static <T1, T2> void loadInto2DCounter(String filename, Class<T1> t1, Class<T2> t2, TwoDimensionalCounter<T1, T2> tdc) throws RuntimeException { try { Constructor<T1> m1 = t1.getConstructor(String.class); Constructor<T2> m2 = t2.getConstructor(String.class); BufferedReader in = IOUtils.getBufferedFileReader(filename);// new // BufferedReader(new // FileReader(filename)); for (String line; (line = in.readLine()) != null;) { String[] tuple = line.trim().split("\t"); String outer = tuple[0]; String inner = tuple[1]; String valStr = tuple[2]; tdc.setCount(m1.newInstance(outer.trim()), m2.newInstance(inner.trim()), Double.parseDouble(valStr.trim())); } in.close(); } catch (Exception e) { throw new RuntimeException(e); } }
public static<T1, T2> void loadInto2DCounter(String filename, Class<T1> t1, Class <T2> t2, TwoDimensionalCounter<T1, T2> tdc) throws RuntimeException { try { Constructor<T1> m1 = t1.getConstructor(String.class); Constructor<T2> m2 = t2.getConstructor(String.class); BufferedReader in = IOUtils.getBufferedFileReader(filename);//new BufferedReader(new FileReader(filename)); for (String line; (line = in.readLine()) != null; ) { String[] tuple = line.trim().split("\t"); String outer = tuple[0]; String inner = tuple[1]; String valStr = tuple[2]; tdc.setCount(m1.newInstance(outer.trim()), m2.newInstance(inner.trim()), Double.parseDouble(valStr.trim())); } in.close(); } catch (Exception e) { throw new RuntimeException(e); } }
private void loadMWMap(String filename) { mwCounter = new TwoDimensionalCounter<>(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)), "UTF-8")); int nLines = 0; for(String line; (line = br.readLine()) != null; nLines++) { String[] toks = line.split("\t"); assert toks.length == 3; mwCounter.setCount(toks[0].trim(), toks[1].trim(), Double.parseDouble(toks[2].trim())); } br.close(); System.err.printf("%s: Loaded %d lines from %s into MWE counter%n", this.getClass().getName(),nLines,filename); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private void loadMWMap(String filename) { mwCounter = new TwoDimensionalCounter<String,String>(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)), "UTF-8")); int nLines = 0; for(String line; (line = br.readLine()) != null; nLines++) { String[] toks = line.split("\t"); assert toks.length == 3; mwCounter.setCount(toks[0].trim(), toks[1].trim(), Double.parseDouble(toks[2].trim())); } br.close(); System.err.printf("%s: Loaded %d lines from %s into MWE counter%n", this.getClass().getName(),nLines,filename); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public static <T1, T2> void loadInto2DCounter(String filename, Class<T1> t1, Class<T2> t2, TwoDimensionalCounter<T1, T2> tdc) throws RuntimeException { try { Constructor<T1> m1 = t1.getConstructor(String.class); Constructor<T2> m2 = t2.getConstructor(String.class); BufferedReader in = IOUtils.getBufferedFileReader(filename);// new // BufferedReader(new // FileReader(filename)); for (String line; (line = in.readLine()) != null;) { String[] tuple = line.trim().split("\t"); String outer = tuple[0]; String inner = tuple[1]; String valStr = tuple[2]; tdc.setCount(m1.newInstance(outer.trim()), m2.newInstance(inner.trim()), Double.parseDouble(valStr.trim())); } in.close(); } catch (Exception e) { throw new RuntimeException(e); } }
private void loadMWMap(String filename) { mwCounter = new TwoDimensionalCounter<>(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)), "UTF-8")); int nLines = 0; for(String line; (line = br.readLine()) != null; nLines++) { String[] toks = line.split("\t"); assert toks.length == 3; mwCounter.setCount(toks[0].trim(), toks[1].trim(), Double.parseDouble(toks[2].trim())); } br.close(); System.err.printf("%s: Loaded %d lines from %s into MWE counter%n", this.getClass().getName(),nLines,filename); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
/** * Produces a new ConditionalCounter. * * @return a new ConditionalCounter, where order of indices is reversed */ @SuppressWarnings( { "unchecked" }) public static <K1, K2> TwoDimensionalCounter<K2, K1> reverseIndexOrder(TwoDimensionalCounter<K1, K2> cc) { // they typing on the outerMF is violated a bit, but it'll work.... TwoDimensionalCounter<K2, K1> result = new TwoDimensionalCounter<K2, K1>((MapFactory) cc.outerMF, (MapFactory) cc.innerMF); for (K1 key1 : cc.firstKeySet()) { ClassicCounter<K2> c = cc.getCounter(key1); for (K2 key2 : c.keySet()) { double count = c.getCount(key2); result.setCount(key2, key1, count); } } return result; }
/** * Produces a new ConditionalCounter. * * @return a new ConditionalCounter, where order of indices is reversed */ @SuppressWarnings( { "unchecked" }) public static <K1, K2> TwoDimensionalCounter<K2, K1> reverseIndexOrder(TwoDimensionalCounter<K1, K2> cc) { // they typing on the outerMF is violated a bit, but it'll work.... TwoDimensionalCounter<K2, K1> result = new TwoDimensionalCounter<>((MapFactory) cc.outerMF, (MapFactory) cc.innerMF); for (K1 key1 : cc.firstKeySet()) { ClassicCounter<K2> c = cc.getCounter(key1); for (K2 key2 : c.keySet()) { double count = c.getCount(key2); result.setCount(key2, key1, count); } } return result; }
/** * Produces a new ConditionalCounter. * * @return a new ConditionalCounter, where order of indices is reversed */ @SuppressWarnings( { "unchecked" }) public static <K1, K2> TwoDimensionalCounter<K2, K1> reverseIndexOrder(TwoDimensionalCounter<K1, K2> cc) { // they typing on the outerMF is violated a bit, but it'll work.... TwoDimensionalCounter<K2, K1> result = new TwoDimensionalCounter<>((MapFactory) cc.outerMF, (MapFactory) cc.innerMF); for (K1 key1 : cc.firstKeySet()) { ClassicCounter<K2> c = cc.getCounter(key1); for (K2 key2 : c.keySet()) { double count = c.getCount(key2); result.setCount(key2, key1, count); } } return result; }
/** * Produces a new ConditionalCounter. * * @return a new ConditionalCounter, where order of indices is reversed */ @SuppressWarnings( { "unchecked" }) public static <K1, K2> TwoDimensionalCounter<K2, K1> reverseIndexOrder(TwoDimensionalCounter<K1, K2> cc) { // they typing on the outerMF is violated a bit, but it'll work.... TwoDimensionalCounter<K2, K1> result = new TwoDimensionalCounter<K2, K1>((MapFactory) cc.outerMF, (MapFactory) cc.innerMF); for (K1 key1 : cc.firstKeySet()) { ClassicCounter<K2> c = cc.getCounter(key1); for (K2 key2 : c.keySet()) { double count = c.getCount(key2); result.setCount(key2, key1, count); } } return result; }