Search in sources :

Example 91 with Splitter

use of com.google.common.base.Splitter in project zemberek-nlp by ahmetaa.

the class AmbiguityStats method noParse.

public void noParse(String... filename) throws IOException {
    Histogram<String> uniques = new Histogram<>(1000000);
    int total = 0;
    for (String file : filename) {
        List<String> lines = readAll(file);
        Splitter splitter = Splitter.on(" ").omitEmptyStrings().trimResults();
        for (String line : lines) {
            for (String s : splitter.split(line)) {
                WordAnalysis results = parser.analyze(s);
                total++;
                if (total % 50000 == 0) {
                    System.out.println("Processed: " + total);
                }
                if (results.analysisCount() == 0) {
                    uniques.add(s);
                }
            }
        }
        System.out.println("Total: " + total);
    }
    Stats st = new Stats(0.0002);
    st.allCounts = (int) uniques.totalCount();
    st.allUniques = uniques.size();
    for (String s : uniques.getSortedList()) {
        int count = uniques.getCount(s);
        if (count > 5) {
            st.significantCounts += count;
            st.significantUniques++;
            System.out.println(s + " : " + count);
        }
    }
    st.dump();
}
Also used : Histogram(zemberek.core.collections.Histogram) Splitter(com.google.common.base.Splitter) WordAnalysis(zemberek.morphology.analysis.WordAnalysis)

Example 92 with Splitter

use of com.google.common.base.Splitter in project netvirt by opendaylight.

the class ElanBridgeManager method getMultiValueMap.

private static Map<String, String> getMultiValueMap(String multiKeyValueStr) {
    if (Strings.isNullOrEmpty(multiKeyValueStr)) {
        return Collections.emptyMap();
    }
    Map<String, String> valueMap = new HashMap<>();
    Splitter splitter = Splitter.on(OTHER_CONFIG_PARAMETERS_DELIMITER);
    for (String keyValue : splitter.split(multiKeyValueStr)) {
        String[] split = keyValue.split(OTHER_CONFIG_KEY_VALUE_DELIMITER, 2);
        if (split.length == 2) {
            valueMap.put(split[0], split[1]);
        }
    }
    return valueMap;
}
Also used : Splitter(com.google.common.base.Splitter) HashMap(java.util.HashMap)

Example 93 with Splitter

use of com.google.common.base.Splitter in project netvirt by opendaylight.

the class NatUtil method getMultiValueMap.

public static Map<String, String> getMultiValueMap(String multiKeyValueStr) {
    if (Strings.isNullOrEmpty(multiKeyValueStr)) {
        return Collections.emptyMap();
    }
    Map<String, String> valueMap = new HashMap<>();
    Splitter splitter = Splitter.on(OTHER_CONFIG_PARAMETERS_DELIMITER);
    for (String keyValue : splitter.split(multiKeyValueStr)) {
        String[] split = keyValue.split(OTHER_CONFIG_KEY_VALUE_DELIMITER, 2);
        if (split.length == 2) {
            valueMap.put(split[0], split[1]);
        }
    }
    return valueMap;
}
Also used : Splitter(com.google.common.base.Splitter) HashMap(java.util.HashMap)

Example 94 with Splitter

use of com.google.common.base.Splitter in project closure-compiler by google.

the class TextDiffFactsBuilder method build.

/**
 * Returns one or more Fact objects representing the difference between the expected and actual
 * text strings, which must be specified by calling their methods before calling this one.
 */
public ImmutableList<Fact> build() {
    try {
        // The diff algorithm expects to work on a list, so we need to split the text into
        // lines.
        final Splitter lineSplitter = Splitter.on('\n');
        final List<String> expectedLines = lineSplitter.splitToList(checkNotNull(expectedText));
        final List<String> actualLines = lineSplitter.splitToList(checkNotNull(actualText));
        final Patch<String> patch = DiffUtils.diff(expectedLines, actualLines);
        final List<String> unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff("expected", "actual", expectedLines, patch, /* contextSize= */
        10);
        return ImmutableList.of(fact(title, unifiedDiff.stream().collect(joining("\n"))));
    } catch (DiffException e) {
        // It may indicate a bug in the diff library itself.
        throw new IllegalStateException(e);
    }
}
Also used : Splitter(com.google.common.base.Splitter) DiffException(com.github.difflib.algorithm.DiffException)

Aggregations

Splitter (com.google.common.base.Splitter)94 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)12 HashSet (java.util.HashSet)10 HashMap (java.util.HashMap)8 File (java.io.File)7 Test (org.junit.Test)7 BufferedReader (java.io.BufferedReader)5 ToString (lombok.ToString)4 NonNull (com.android.annotations.NonNull)3 InputStreamReader (java.io.InputStreamReader)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)3 Histogram (zemberek.core.collections.Histogram)3 WordAnalysis (zemberek.morphology.analysis.WordAnalysis)3 CharMatcher (com.google.common.base.CharMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CharSource (com.google.common.io.CharSource)2