List of usage examples for java.util Set retainAll
boolean retainAll(Collection<?> c);
From source file:edu.usc.polar.CompositeNERAgreementParser.java
public static void CompositeNER(String doc, String args[]) { try {/* w ww. j a v a 2 s .c o m*/ String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); String metaValue = metadata.toString(); System.out.println(metaValue + "Desc:: " + metadata.get("description")); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); name = name.replace("\\", "."); Map<String, Set<String>> list = getCoreNLP(text); Map<String, Set<String>> list1 = getOpenNLP(text); Map<String, Set<String>> list2 = getNLTKRest(text); Set<String> NLTKRestSet = combineSets(list2); Set<String> coreNLPSet = combineSets(list); Set<String> openNLPSet = combineSets(list1); /* System.out.println("list coreNLP"+JSONStringify(coreNLPSet).toJSONString()); System.out.println("list openNLPSet"+openNLPSet); System.out.println("list NLTKRestSet"+NLTKRestSet); */ JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("OpenNLP", JSONStringify(openNLPSet)); jsonObj.put("NLTKRest", JSONStringify(NLTKRestSet)); jsonObj.put("CoreNLP", JSONStringify(coreNLPSet)); Set<String> union = new HashSet(); union.addAll(NLTKRestSet); union.addAll(coreNLPSet); union.addAll(openNLPSet); jsonObj.put("Union", JSONStringify(union)); Set<String> intersection = new HashSet(); intersection.addAll(union); intersection.retainAll(coreNLPSet); intersection.retainAll(openNLPSet); intersection.retainAll(NLTKRestSet); jsonObj.put("Agreement", JSONStringify(intersection)); /* System.out.println(name+"\n"+openNLPSet.size()+openNLPSet.toString()+ "\n"+coreNLPSet.size()+coreNLPSet.toString()+ "\n"+NLTKRestSet.size()+NLTKRestSet.toArray()+ "\n"+intersection.size()+intersection.toArray()+ "\n"+union.size()+union.toArray()); */ //jsonObj.put("metadata",metaValue.replaceAll("\\s\\s+|\n|\t"," ")); jsonArray.add(jsonObj); if (intersection.size() > 0) { jsonAgree.add(jsonObj); JSONArray jArr = new JSONArray(); jArr.add(jsonObj); metadata.add("CompositeNER", jArr.toJSONString()); } } catch (Exception e) { System.out.println("ERROR : OpenNLP" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }
From source file:org.apache.lens.cube.parse.StorageUtil.java
private static Map<String, Set<FactPartition>> getMaxCoveringStorage( final Map<String, Set<FactPartition>> storageCoveringMap, Set<FactPartition> queriedParts) { int coveringcount = 0; int maxCoveringCount = 0; String maxCoveringStorage = null; Set<FactPartition> maxCoveringSet = null; for (Map.Entry<String, Set<FactPartition>> entry : storageCoveringMap.entrySet()) { Set<FactPartition> coveringSet = new TreeSet<FactPartition>(); coveringSet.addAll(entry.getValue()); coveringSet.retainAll(queriedParts); coveringcount = coveringSet.size(); if (coveringcount > maxCoveringCount) { maxCoveringCount = coveringcount; maxCoveringStorage = entry.getKey(); maxCoveringSet = coveringSet; }/*www.ja va2 s.co m*/ } return Collections.singletonMap(maxCoveringStorage, maxCoveringSet); }
From source file:org.talend.core.classloader.ClassLoaderFactory.java
/** * DOC ycbai Comment method "getCustomClassLoader". * /* w w w . j a v a2 s. co m*/ * @param index * @param libraries * @return the classLoader by specific libraries */ public static DynamicClassLoader getCustomClassLoader(String index, Set<String> libraries) { if (libraries == null || libraries.size() == 0) { return null; } DynamicClassLoader classLoader = getClassLoader(index); if (classLoader == null) { classLoader = createCustomClassLoader(index, libraries); } else { boolean changed; Set<String> oldLibraries = classLoader.getLibraries(); Set<String> oldLibrariesClone = new HashSet<String>(oldLibraries); changed = oldLibrariesClone.retainAll(libraries); if (!changed) { Set<String> newLibrariesClone = new HashSet<String>(libraries); changed = newLibrariesClone.retainAll(oldLibraries); } if (changed) { File libFolder = new File(classLoader.getLibStorePath()); if (libFolder.exists()) { FilesUtils.removeFolder(libFolder, true); } classLoader = createCustomClassLoader(index, libraries); } } return classLoader; }
From source file:ubic.pubmedgate.interactions.evaluation.RecallCuratorsCombined.java
public static void splitBySentences() throws Exception { String baseFolder = Config.config.getString("whitetext.iteractions.ppiBaseFolder") + "Saved Results/SL/CC/NegFixFullOnUnseen/"; String corpusFilename = Config.config.getString("whitetext.iteractions.ppiBaseFolder") + "Corpora/Original-Modified/WhiteTextUnseen.orig.xml"; String trainingSet = "WhiteTextNegFixFull"; String testSet = "WhiteTextUnseen"; String annotationSet = "Mallet"; SLOutputReader SLReader = new SLOutputReader(trainingSet, testSet, baseFolder); log.info("Score size:" + SLReader.getScores().size()); GateInterface p2g = new GateInterface(); p2g.setUnSeenCorpNull();/*www. j ava 2 s . co m*/ p2g.setNamedCorpNull("PubMedUnseenJNChem"); // p2g.setNamedCorpNull("PubMedUnseenJCN"); p2g.setNamedCorpNull("PubMedUnseenMScan1"); p2g.setNamedCorpNull("PubMedUnseenMScan2"); AirolaXMLReader XMLReader = new AirolaXMLReader(corpusFilename, p2g, annotationSet); Set<String> sentences = XMLReader.getAllSentences(); log.info("All sentences:" + sentences.size()); List<String> posPredictedPairs = SLReader.getPositivePredictions(); StringToStringSetMap sentenceIDToPairs = XMLReader.getSentenceIDToPairs(); int sentencesWithPosPrecitions = 0; int sentencesWithOnlyNegPrecitions = 0; int pairsFromSenPosPrecitions = 0; int posPairsFromSenPosPrecitions = 0; Set<String> pairsFromSenPosPrecitionsSet = new HashSet<String>(); int pairsFromSenOnlyNegPrecitions = 0; Set<String> pairsFromSenOnlyNegPrecitionsSet = new HashSet<String>(); Set<String> pairsToUse = new HashSet<String>(); log.info("All pairs:" + SLReader.getAll().size()); for (String sentence : sentences) { Set<String> pairs = new HashSet<String>(sentenceIDToPairs.get(sentence)); int pairCount = pairs.size(); pairs.retainAll(posPredictedPairs); if (pairs.size() > 0) { sentencesWithPosPrecitions++; pairsFromSenPosPrecitions += pairCount; // just positives posPairsFromSenPosPrecitions += pairs.size(); pairsFromSenPosPrecitionsSet.addAll(sentenceIDToPairs.get(sentence)); } else { sentencesWithOnlyNegPrecitions++; pairsFromSenOnlyNegPrecitions += pairCount; pairsFromSenOnlyNegPrecitionsSet.addAll(sentenceIDToPairs.get(sentence)); } } log.info("sentencesWithOnlyNegPrecitions:" + sentencesWithOnlyNegPrecitions); log.info("pairsFromSenOnlyNegPrecitions:" + pairsFromSenOnlyNegPrecitions); log.info(""); log.info("sentencesWithPosPrecitions:" + sentencesWithPosPrecitions); log.info("pairsFromSenPosPrecitions:" + pairsFromSenPosPrecitions); log.info("posPairsFromSenPosPrecitions, positive pairs in sentences with at least one positive:" + posPairsFromSenPosPrecitions); log.info("pairsToUse:" + pairsToUse.size()); RecallCuratorsCombined combined = new RecallCuratorsCombined(); combined.load6000Set(); combined.printAllStats(); System.out.println(); System.out.println(); combined.retainPairs(pairsFromSenPosPrecitionsSet); combined.printAllStats(); System.out.println(); System.out.println(); combined = new RecallCuratorsCombined(); combined.load6000Set(); combined.retainPairs(pairsFromSenOnlyNegPrecitionsSet); combined.printAllStats(); // combined.printDisagreements( "Accept" ); }
From source file:common.Utilities.java
public static double getCosineSim(Map<Integer, Integer> targetMap, Map<Integer, Integer> nMap) { Set<Integer> both = new HashSet<Integer>(targetMap.keySet()); both.retainAll(nMap.keySet()); double scalar = 0.0, norm1 = 0.0, norm2 = 0.0; for (int k : both) scalar += (targetMap.get(k) * nMap.get(k)); for (int k : targetMap.keySet()) norm1 += (targetMap.get(k) * targetMap.get(k)); for (int k : nMap.keySet()) norm2 += (nMap.get(k) * nMap.get(k)); return scalar / Math.sqrt(norm1 * norm2); }
From source file:common.Utilities.java
public static double getCosineFloatSim(Map<Integer, Double> targetMap, Map<Integer, Double> nMap) { Set<Integer> both = new HashSet<Integer>(targetMap.keySet()); both.retainAll(nMap.keySet()); double scalar = 0.0, norm1 = 0.0, norm2 = 0.0; for (int k : both) scalar += (targetMap.get(k) * nMap.get(k)); for (int k : targetMap.keySet()) norm1 += (targetMap.get(k) * targetMap.get(k)); for (int k : nMap.keySet()) norm2 += (nMap.get(k) * nMap.get(k)); return scalar / Math.sqrt(norm1 * norm2); }
From source file:tools.xor.util.ClassUtil.java
public static boolean intersectsTags(String[] tags, String[] otherTags) { Set<String> commonTags = new HashSet<String>(Arrays.asList(tags)); commonTags.retainAll(new HashSet<String>(Arrays.asList(otherTags))); if (commonTags.isEmpty()) { // applies to different tags so they do not overlap return false; }// w ww . j a v a2 s. c o m return true; }
From source file:common.Utilities.java
public static double getJaccardSim(Map<Integer, Integer> targetMap, Map<Integer, Integer> nMap) { Set<Integer> unionSet = new HashSet<Integer>(targetMap.keySet()); Set<Integer> intersectSet = new HashSet<Integer>(targetMap.keySet()); unionSet.addAll(nMap.keySet());//from ww w .java2 s. co m intersectSet.retainAll(nMap.keySet()); return (double) intersectSet.size() / (double) unionSet.size(); }
From source file:common.Utilities.java
public static double getJaccardFloatSim(Map<Integer, Double> targetMap, Map<Integer, Double> nMap) { Set<Integer> unionSet = new HashSet<Integer>(targetMap.keySet()); Set<Integer> intersectSet = new HashSet<Integer>(targetMap.keySet()); unionSet.addAll(nMap.keySet());/*from w ww . j av a2 s . c o m*/ intersectSet.retainAll(nMap.keySet()); return (double) intersectSet.size() / (double) unionSet.size(); }
From source file:org.apache.accumulo.core.util.LocalityGroupUtil.java
public static Map<String, Set<ByteSequence>> getLocalityGroups(AccumuloConfiguration acuconf) throws LocalityGroupConfigurationError { Map<String, Set<ByteSequence>> result = new HashMap<String, Set<ByteSequence>>(); String[] groups = acuconf.get(Property.TABLE_LOCALITY_GROUPS).split(","); for (String group : groups) { if (group.length() > 0) result.put(group, new HashSet<ByteSequence>()); }//w w w . java 2 s . com HashSet<ByteSequence> all = new HashSet<ByteSequence>(); for (Entry<String, String> entry : acuconf) { String property = entry.getKey(); String value = entry.getValue(); String prefix = Property.TABLE_LOCALITY_GROUP_PREFIX.getKey(); if (property.startsWith(prefix)) { // this property configures a locality group, find out which one: String group = property.substring(prefix.length()); String[] parts = group.split("\\."); group = parts[0]; if (result.containsKey(group)) { if (parts.length == 1) { Set<ByteSequence> colFamsSet = decodeColumnFamilies(value); if (!Collections.disjoint(all, colFamsSet)) { colFamsSet.retainAll(all); throw new LocalityGroupConfigurationError("Column families " + colFamsSet + " in group " + group + " is already used by another locality group"); } all.addAll(colFamsSet); result.put(group, colFamsSet); } } } } // result.put("", all); return result; }