List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:amie.keys.CombinationsExplorationNew.java
/** * * @param ruleToExtendWith//from w w w .jav a 2 s . co m * @param ruleToGraphNewFirstLevel * @param ruleToGraphNewLastLevel * @param kb */ private static void discoverConditionalKeysPerLevel(HashMap<Rule, HashSet<String>> ruleToExtendWith, HashMap<Rule, GraphNew> ruleToGraphNewFirstLevel, HashMap<Rule, GraphNew> ruleToGraphNewLastLevel) { HashMap<Rule, GraphNew> ruleToGraphNewThisLevel = new HashMap<>(); for (Rule currentRule : ruleToExtendWith.keySet()) { for (String conditionProperty : ruleToExtendWith.get(currentRule)) { if (Utilities.getRelationIds(currentRule, property2Id).last() > property2Id .get(conditionProperty)) { GraphNew graph = ruleToGraphNewLastLevel.get(currentRule); GraphNew currentGraphNew = (GraphNew) graph.clone(); Integer propertyId = property2Id.get(conditionProperty); HashSet<Integer> propertiesSet = new HashSet<>(); propertiesSet.add(propertyId); Node node = currentGraphNew.createNode(propertiesSet); node.toExplore = false; Iterable<Rule> conditions = Utilities.getConditions(currentRule, conditionProperty, (int) support, kb); for (Rule conditionRule : conditions) { Rule complementaryRule = getComplementaryRule(conditionRule); if (!ruleToGraphNewFirstLevel.containsKey(complementaryRule)) { // We should never fall in this case for (Rule r : ruleToGraphNewFirstLevel.keySet()) { System.out.println(r.getDatalogBasicRuleString()); } System.out.println(complementaryRule.getDatalogBasicRuleString()); System.out.println(complementaryRule + " not found in the first level graph"); } GraphNew complementaryGraphNew = ruleToGraphNewFirstLevel.get(complementaryRule); GraphNew newGraphNew = (GraphNew) currentGraphNew.clone(); HashSet<Integer> conditionProperties = new HashSet<>(); conditionProperties.addAll(getRelations(conditionRule, property2Id)); conditionProperties.addAll(getRelations(currentRule, property2Id)); newGraphNew = mergeGraphNews(newGraphNew, complementaryGraphNew, newGraphNew.topGraphNodes(), conditionProperties); discoverConditionalKeysForComplexConditions(newGraphNew, newGraphNew.topGraphNodes(), conditionRule); ruleToGraphNewThisLevel.put(conditionRule, newGraphNew); } } } } HashMap<Rule, HashSet<String>> newRuleToExtendWith = new HashMap<>(); for (Rule conRule : ruleToGraphNewThisLevel.keySet()) { GraphNew newGraphNew = ruleToGraphNewThisLevel.get(conRule); for (Node node : newGraphNew.topGraphNodes()) { HashSet<String> properties = new HashSet<>(); if (node.toExplore) { Iterator<Integer> it = node.set.iterator(); int prop = it.next(); String propertyStr = id2Property.get(prop); properties.add(propertyStr); } if (properties.size() != 0) { newRuleToExtendWith.put(conRule, properties); } } } if (newRuleToExtendWith.size() != 0) { discoverConditionalKeysPerLevel(newRuleToExtendWith, ruleToGraphNewFirstLevel, ruleToGraphNewThisLevel); } }
From source file:edu.pitt.csb.stability.StabilitySearch.java
public static Set<Integer> subSampleIndices(int N, int subSize) { List<Integer> indices = new ArrayList<Integer>(N); for (int i = 0; i < N; i++) { indices.add(i);/*from w w w. java2 s. c om*/ } Collections.shuffle(indices); HashSet<Integer> samp = new HashSet<Integer>(subSize); for (int i = 0; i < subSize; i++) { samp.add(indices.get(i)); } return samp; }
From source file:dk.statsbiblioteket.doms.licensemodule.validation.LicenseValidator.java
public static ArrayList<String> filterGroups(ArrayList<License> licenses, ArrayList<String> presentationTypes) { HashSet<String> groups = new HashSet<String>(); for (License current : licenses) { for (LicenseContent currentContent : current.getLicenseContents()) { for (Presentation currentPresentation : currentContent.getPresentations()) { if (presentationTypes.contains(currentPresentation.getKey())) { groups.add(currentContent.getName()); }//from www . j av a 2 s . com } } } return new ArrayList<String>(groups); }
From source file:com.eTilbudsavis.etasdk.model.Catalog.java
/** * A factory method for converting {@link JSONObject} into a POJO. * @param catalog A {@link JSONObject} in the format of a valid API v2 catalog response * @return A Catalog object//from w w w .j a va 2 s . c om */ public static Catalog fromJSON(JSONObject jCatalog) { Catalog catalog = new Catalog(); if (jCatalog == null) { return catalog; } try { catalog.setId(Json.valueOf(jCatalog, JsonKey.ID)); catalog.setErn(Json.valueOf(jCatalog, JsonKey.ERN)); catalog.setLabel(Json.valueOf(jCatalog, JsonKey.LABEL)); catalog.setBackground(Json.colorValueOf(jCatalog, JsonKey.BACKGROUND)); Date runFrom = Utils.stringToDate(Json.valueOf(jCatalog, JsonKey.RUN_FROM)); catalog.setRunFrom(runFrom); Date runTill = Utils.stringToDate(Json.valueOf(jCatalog, JsonKey.RUN_TILL)); catalog.setRunTill(runTill); catalog.setPageCount(Json.valueOf(jCatalog, JsonKey.PAGE_COUNT, 0)); catalog.setOfferCount(Json.valueOf(jCatalog, JsonKey.OFFER_COUNT, 0)); catalog.setBranding(Branding.fromJSON(jCatalog.getJSONObject(JsonKey.BRANDING))); catalog.setDealerId(Json.valueOf(jCatalog, JsonKey.DEALER_ID)); catalog.setDealerUrl(Json.valueOf(jCatalog, JsonKey.DEALER_URL)); catalog.setStoreId(Json.valueOf(jCatalog, JsonKey.STORE_ID)); catalog.setStoreUrl(Json.valueOf(jCatalog, JsonKey.STORE_URL)); catalog.setDimension(Dimension.fromJSON(jCatalog.getJSONObject(JsonKey.DIMENSIONS))); catalog.setImages(Images.fromJSON(jCatalog.getJSONObject(JsonKey.IMAGES))); if (jCatalog.has(JsonKey.CATEGORY_IDS)) { JSONArray jCats = jCatalog.getJSONArray(JsonKey.CATEGORY_IDS); HashSet<String> cat = new HashSet<String>(jCats.length()); for (int i = 0; i < jCats.length(); i++) { cat.add(jCats.getString(i)); } catalog.setCatrgoryIds(cat); } catalog.setPdfUrl(Json.valueOf(jCatalog, JsonKey.PDF_URL)); if (jCatalog.has(JsonKey.SDK_DEALER)) { JSONObject jDealer = Json.getObject(jCatalog, JsonKey.SDK_DEALER, null); catalog.setDealer(Dealer.fromJSON(jDealer)); } if (jCatalog.has(JsonKey.SDK_STORE)) { JSONObject jStore = Json.getObject(jCatalog, JsonKey.SDK_STORE, null); catalog.setStore(Store.fromJSON(jStore)); } if (jCatalog.has(JsonKey.SDK_PAGES)) { JSONArray jPages = Json.getArray(jCatalog, JsonKey.SDK_PAGES); List<Images> pages = new ArrayList<Images>(jPages.length()); for (int i = 0; i < jPages.length(); i++) { pages.add(Images.fromJSON(jPages.getJSONObject(i))); } catalog.setPages(pages); } // TODO Fix HotspotsMap so it can be JSON'ed } catch (JSONException e) { EtaLog.e(TAG, "", e); } return catalog; }
From source file:edu.stanford.muse.index.NER.java
public static void main2(String args[]) throws IOException, ClassNotFoundException { String text = "Rishabh has so far not taken to drama, so it was wonderful to see him involved and actively participating. "; boolean normalizeByLength = false; System.err.println("Started reading"); long start_time = System.currentTimeMillis(); List<String> names = new ArrayList<String>(); HashSet<String> namesAdded = new HashSet<String>(); long end_time = System.currentTimeMillis(); for (String name : names) { if (!namesAdded.contains(name)) { System.out.println(name); namesAdded.add(name); }/*from w w w . j a v a2 s . c o m*/ } System.err.println("Reading done in " + (end_time - start_time)); start_time = System.currentTimeMillis(); List<Pair<String, Float>> entities = namesFromText(text, true, NER.defaultTokenTypeWeights, normalizeByLength, 1); end_time = System.currentTimeMillis(); System.err.println("Done name recognition in: " + (end_time - start_time)); for (Pair<String, Float> name : entities) { System.out.println(name.getFirst() + " : " + name.getSecond()); } }
From source file:com.helpinput.core.Utils.java
public static HashSet<String> stringToHash(String source, String split) { HashSet<String> hashset = new HashSet<String>(); String[] fieldNames = source.split(split); for (String str : fieldNames) { hashset.add(str.trim()); }/*from w w w .j av a 2s . c o m*/ return hashset; }
From source file:io.hops.common.INodeUtil.java
public static Set<String> findPathsByLeaseHolder(String holder) throws StorageException { HashSet<String> paths = new HashSet<>(); LeaseDataAccess<Lease> lda = (LeaseDataAccess) HdfsStorageFactory.getDataAccess(LeaseDataAccess.class); Lease rcLease = lda.findByPKey(holder, Lease.getHolderId(holder)); if (rcLease == null) { return paths; }/* w w w . j a v a 2s. co m*/ LeasePathDataAccess pda = (LeasePathDataAccess) HdfsStorageFactory.getDataAccess(LeasePathDataAccess.class); Collection<LeasePath> rclPaths = pda.findByHolderId(rcLease.getHolderID()); for (LeasePath lp : rclPaths) { paths.add(lp.getPath()); } return paths; }
From source file:edu.psu.citeseerx.updates.IndexUpdateManager.java
/** * Builds a list of author normalizations to create more flexible * author search./*w w w .ja v a 2 s . c o m*/ * @param names * @return */ private static List<String> buildAuthorNorms(List<String> names) { HashSet<String> norms = new HashSet<String>(); for (String name : names) { name = name.replaceAll("[^\\p{L} ]", ""); StringTokenizer st = new StringTokenizer(name); String[] tokens = new String[st.countTokens()]; int counter = 0; while (st.hasMoreTokens()) { tokens[counter] = st.nextToken(); counter++; } norms.add(joinStringArray(tokens)); if (tokens.length > 2) { String[] n1 = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { if (i < tokens.length - 1) { n1[i] = Character.toString(tokens[i].charAt(0)); } else { n1[i] = tokens[i]; } } String[] n2 = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { if (i > 0 && i < tokens.length - 1) { n2[i] = Character.toString(tokens[i].charAt(0)); } else { n2[i] = tokens[i]; } } norms.add(joinStringArray(n1)); norms.add(joinStringArray(n2)); } if (tokens.length > 1) { String[] n3 = new String[2]; n3[0] = tokens[0]; n3[1] = tokens[tokens.length - 1]; String[] n4 = new String[2]; n4[0] = Character.toString(tokens[0].charAt(0)); n4[1] = tokens[tokens.length - 1]; norms.add(joinStringArray(n3)); norms.add(joinStringArray(n4)); } } ArrayList<String> normList = new ArrayList<String>(); for (Iterator<String> it = norms.iterator(); it.hasNext();) { normList.add(it.next()); } return normList; }
From source file:javadepchecker.Main.java
private static boolean checkPkg(File env) { boolean needed = true; HashSet<String> pkgs = new HashSet<String>(); Collection<String> deps = null; BufferedReader in = null;/*from w ww . ja va 2s. com*/ try { Pattern dep_re = Pattern.compile("^DEPEND=\"([^\"]*)\"$"); Pattern cp_re = Pattern.compile("^CLASSPATH=\"([^\"]*)\"$"); String line; in = new BufferedReader(new FileReader(env)); while ((line = in.readLine()) != null) { Matcher m = dep_re.matcher(line); if (m.matches()) { String atoms = m.group(1); for (String atom : atoms.split(":")) { String pkg = atom; if (atom.contains("@")) { pkg = atom.split("@")[1]; } pkgs.add(pkg); } continue; } m = cp_re.matcher(line); if (m.matches()) { Main classParser = new Main(); for (String jar : m.group(1).split(":")) { classParser.processJar(new JarFile(image + jar)); } deps = classParser.getDeps(); } } for (String pkg : pkgs) { if (!depNeeded(pkg, deps)) { System.out.println(pkg); needed = false; } } } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } finally { try { in.close(); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } return needed; }
From source file:org.metaservice.core.AbstractDispatcher.java
public static List<Statement> getGeneratedStatements(RepositoryConnection resultConnection, Set<Statement> loadedStatements) throws RepositoryException { RepositoryResult<Statement> all = resultConnection.getStatements(null, null, null, true); ArrayList<Statement> allList = new ArrayList<>(); HashSet<Resource> undefined = new HashSet<>(); while (all.hasNext()) { Statement s = all.next(); if (!loadedStatements.contains(s)) { if (s.getPredicate().equals(RDFS.SUBPROPERTYOF) || s.getPredicate().equals(RDFS.SUBCLASSOF) || s.getPredicate().equals(RDF.TYPE) && s.getObject().equals(RDFS.RESOURCE) || s.getPredicate().equals(RDF.TYPE) && s.getObject().equals(OWL.THING) || s.getPredicate().equals(RDF.TYPE) && s.getObject().equals(RDF.PROPERTY)) { if (!s.getSubject().stringValue().startsWith("http://metaservice.org/d/")) { LOGGER.debug("UNDEFINED {} {} {}", s.getSubject(), s.getPredicate(), s.getObject()); undefined.add(s.getSubject()); }/*from ww w . ja va 2 s .c om*/ } else { if (s.getSubject() instanceof BNode || s.getObject() instanceof BNode) { LOGGER.error("ATTENTION - BNodes are not supported by Metaservice, skipping statement"); continue; } allList.add(s); } } } if (undefined.size() != 0) { //grep for logfiles: //grep "not defi" *| sed -e 's/^.*WARN.*define://' | uniq | sort | uniq | sed -e 's/,/\n/g' | tr -d ' ' | sort | uniq LOGGER.warn("Did not define: {}", StringUtils.join(undefined, ", ")); } return allList; }