Search in sources :

Example 56 with Splitter

use of com.google.common.base.Splitter in project BuildCraft by BuildCraft.

the class IMCHandlerTransport method processBlacklistFacadeIMC.

// TODO: Merge with AddFacadeIMC
public static void processBlacklistFacadeIMC(IMCEvent event, IMCMessage m) {
    try {
        if (m.isStringMessage()) {
            Splitter splitter = Splitter.on("@").trimResults();
            String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class);
            if (array.length <= 0 || array.length >= 3) {
                BCLog.logger.info(String.format("Received an invalid blacklist-facade request %s from mod %s", m.getStringValue(), m.getSender()));
            } else {
                String blockName = array[0];
                Integer metaId = array.length == 1 ? -1 : Ints.tryParse(array[1]);
                if (Strings.isNullOrEmpty(blockName) || metaId == null) {
                    BCLog.logger.info(String.format("Received an invalid blacklist-facade request %s from mod %s", m.getStringValue(), m.getSender()));
                } else {
                    Block block = Block.blockRegistry.getObject(new ResourceLocation(blockName));
                    if (metaId < 0) {
                        ItemFacade.blacklistFacade(block);
                    } else {
                        ItemFacade.blacklistFacade(block.getStateFromMeta(metaId));
                    }
                }
            }
        } else if (m.isItemStackMessage()) {
            ItemStack modItemStack = m.getItemStackValue();
            Block block = Block.getBlockFromItem(modItemStack.getItem());
            if (block != null) {
                if (modItemStack.getItemDamage() < 0) {
                    ItemFacade.blacklistFacade(block);
                } else {
                    ItemFacade.blacklistFacade(block.getStateFromMeta(modItemStack.getItemDamage()));
                }
            }
        }
    } catch (Throwable e) {
    }
}
Also used : Splitter(com.google.common.base.Splitter) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 57 with Splitter

use of com.google.common.base.Splitter in project cdap by caskdata.

the class MapReduceContainerHelper method addMapReduceClassPath.

/**
 * Adds the classpath to be used in MapReduce job execution based on the given {@link Configuration}.
 *
 * @param hConf the configuration for the job.
 * @param result a list for appending MR framework classpath
 * @return the same {@code result} list from the argument
 */
public static <T extends Collection<String>> T addMapReduceClassPath(Configuration hConf, T result) {
    String framework = hConf.get(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH);
    // For classpath config get from the hConf, we splits it with both "," and ":" because one can set
    // the conf with something like "path1,path2:path3" and
    // it should become "path1:path2:path3" in the target JVM process
    Splitter splitter = Splitter.on(Pattern.compile(",|" + File.pathSeparatorChar)).trimResults().omitEmptyStrings();
    // Otherwise, only use the mapreduce.application.classpath
    if (framework == null) {
        Iterable<String> yarnAppClassPath = Arrays.asList(hConf.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH, YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
        Iterables.addAll(result, yarnAppClassPath);
    }
    // Add MR application classpath
    Iterables.addAll(result, splitter.split(hConf.get(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH, MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH)));
    return result;
}
Also used : Splitter(com.google.common.base.Splitter)

Example 58 with Splitter

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

the class AmbiguityStats method ambiguousWordStats.

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

Example 59 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)) {
                List<WordAnalysis> results = parser.getWordAnalyzer().analyze(TurkishAlphabet.INSTANCE.normalize(s));
                total++;
                if (total % 50000 == 0) {
                    System.out.println("Processed: " + total);
                }
                if (results.size() == 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 60 with Splitter

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

the class ElanBridgeManager method getMultiValueMap.

@Override
public 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)

Aggregations

Splitter (com.google.common.base.Splitter)86 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)12 HashSet (java.util.HashSet)10 File (java.io.File)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 BufferedReader (java.io.BufferedReader)4 NonNull (com.android.annotations.NonNull)3 URI (java.net.URI)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)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 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2