List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:de.fuberlin.agcsw.svont.changedetection.smartcex.PartitionEL.java
/** * Splits the given ontology into two partitions: The set of OWL EL * compliant axioms and the set of axioms which are not compliant with the * OWL EL profile. The EL compliant partition is stored in the left part of * resulting pair, and the EL non-compliant partition is stored in the right * part./*from ww w.jav a2 s.c o m*/ * * @param sourceOnto * The source ontology to be partitioned. * @param compatibilityMode * Specifies the reasoner with which the resulting partition * should be compatible (e.g. Pellet has a different notion of EL * than other reasoners). * @return A pair containing two ontologies. The left part is the partition * of the source ontology with all EL-compliant axioms. The right * part is the partition of the source ontology with all * non-EL-compliant axioms. If the source ontology already conforms * to the OWL-EL profile, then the left part of the result contains * the source ontology, and the right part is null. * @throws OWLOntologyCreationException * If there is an error loading the source ontology. * @throws IllegalAccessException * @throws InstantiationException */ public static Pair<OWLOntology, OWLOntology> partition(OWLOntology sourceOnto, ReasonerCompatibilityMode compatibilityMode) throws OWLOntologyCreationException, InstantiationException, IllegalAccessException { OWLProfile elProfile = compatibilityMode.getProfileClass().newInstance(); OWLProfileReport report = elProfile.checkOntology(sourceOnto); if (report.isInProfile()) { return new ImmutablePair<OWLOntology, OWLOntology>(sourceOnto, null); } HashSet<OWLAxiom> nonELAxioms = new HashSet<OWLAxiom>(); Set<OWLProfileViolation> violations = report.getViolations(); for (OWLProfileViolation violation : violations) { nonELAxioms.add(violation.getAxiom()); } OWLOntologyID ontologyID = sourceOnto.getOntologyID(); IRI ontologyIRI = ontologyID.getOntologyIRI(); IRI targetELOntologyIRI = IRI.create(ontologyIRI.toString() + "/ELpart"); IRI targetNonELOntologyIRI = IRI.create(ontologyIRI.toString() + "/nonELpart"); OWLOntologyManager targetELOntoManager = OWLManager.createOWLOntologyManager(); targetELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper()); OWLOntology targetELOnto = targetELOntoManager.createOntology(new OWLOntologyID(targetELOntologyIRI)); OWLOntologyManager targetNonELOntoManager = OWLManager.createOWLOntologyManager(); targetNonELOntoManager.addIRIMapper(new NonMappingOntologyIRIMapper()); OWLOntology targetNonELOnto = targetNonELOntoManager .createOntology(new OWLOntologyID(targetNonELOntologyIRI)); Set<OWLAxiom> allAxioms = sourceOnto.getAxioms(); for (OWLAxiom axiom : allAxioms) { if (nonELAxioms.contains(axiom)) { targetNonELOntoManager.addAxiom(targetNonELOnto, axiom); System.out.println("- " + axiom); } else { targetELOntoManager.addAxiom(targetELOnto, axiom); System.out.println("+ " + axiom); } } return new ImmutablePair<OWLOntology, OWLOntology>(targetELOnto, targetNonELOnto); }
From source file:com.milaboratory.core.clustering.ClusteringTest.java
private static Cluster<TestObject> getRandomTestCluster(NucleotideSequence sequence, int color, int depth, int maxChildren, int maxCount, int delta, long seed) { assert delta * depth < maxCount; Cluster<TestObject> head = new Cluster<>(new TestObject(maxCount, sequence, color)); HashSet<NucleotideSequence> nucleotideSequences = new HashSet<>(); nucleotideSequences.add(sequence); addRandomTestCluster(head, color, nucleotideSequences, maxChildren, depth, delta, new Well19937a(seed)); return head;// ww w. j a va 2 s.c om }
From source file:com.vitembp.embedded.hardware.SerialBusSensorFactory.java
/** * Builds sensor instances for serial a bus. * @param bus The bus to build sensor objects for. * @return The set of sensors connected to the bus. *//* w ww. j a va2 s . co m*/ static Set<Sensor> getSerialSensors(SerialBus bus) throws IOException { try { HashSet<Sensor> toReturn = new HashSet<>(); // query serial bus for sensor information bus.writeBytes(new byte[] { 'i' }); byte[] respBytes = bus.readBytes(36); String resp = new String(respBytes, Charsets.UTF_8); if (DistanceVL53L0X.TYPE_UUID.toString().equals(resp)) { toReturn.add(new DistanceVL53L0X(bus)); } else if (DistanceVL6180X.TYPE_UUID.toString().equals(resp)) { toReturn.add(new DistanceVL6180X(bus)); } else if (AccelerometerFXOS8700CQSerial.TYPE_UUID.toString().equals(resp)) { toReturn.add(new AccelerometerFXOS8700CQSerial(bus)); } else if (RotaryEncoderEAW0J.TYPE_UUID.toString().equals(resp)) { toReturn.add(new RotaryEncoderEAW0J(bus)); } else if (AccelerometerADXL326.TYPE_UUID.toString().equals(resp)) { toReturn.add(new AccelerometerADXL326(bus)); } return toReturn; } catch (IOException ex) { throw new IOException("Error enumerating bus: " + bus.getName(), ex); } }
From source file:com.jetyun.pgcd.rpc.localarg.LocalArgController.java
/** * Registers a Class to be removed from the exported method signatures and * instead be resolved locally using context information from the transport. * /*from w ww .java2 s .c om*/ * TODO: make the order that the variables are given to this function the * same as the variables are given to LocalArgResolverData * * @param argClazz * The class to be resolved locally * @param argResolver * The user defined class that resolves the and returns the * method argument using transport context information * @param contextInterface * The type of transport Context object the callback is * interested in eg. HttpServletRequest.class for the servlet * transport */ public static void registerLocalArgResolver(Class argClazz, Class contextInterface, LocalArgResolver argResolver) { synchronized (localArgResolverMap) { HashSet resolverSet = (HashSet) localArgResolverMap.get(argClazz); if (resolverSet == null) { resolverSet = new HashSet(); localArgResolverMap.put(argClazz, resolverSet); } resolverSet.add(new LocalArgResolverData(argResolver, argClazz, contextInterface)); } log.info("registered local arg resolver " + argResolver.getClass().getName() + " for local class " + argClazz.getName() + " with context " + contextInterface.getName()); }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * ?/* ww w . j a va2s . c o m*/ * @param vals * @return */ public static <T> Set<T> loadSet(T[] vals) { HashSet<T> set = new HashSet<>(); for (T v : vals) if (v != null) set.add(v); return set; }
From source file:com.facebook.model.JsonUtil.java
static Set<Map.Entry<String, Object>> jsonObjectEntrySet(JSONObject jsonObject) { HashSet<Map.Entry<String, Object>> result = new HashSet<Map.Entry<String, Object>>(); @SuppressWarnings("unchecked") Iterator<String> keys = jsonObject.keys(); while (keys.hasNext()) { String key = keys.next(); Object value = jsonObject.opt(key); result.add(new JSONObjectEntry(key, value)); }// w w w . j av a 2s . c o m return result; }
From source file:com.github.steveash.jg2p.align.FilterWalkerDecorator.java
public static Set<Pair<String, String>> readFromFile(File file) throws IOException { Splitter splitter = Splitter.on('^').trimResults(); List<String> lines = Files.readLines(file, Charsets.UTF_8); HashSet<Pair<String, String>> result = Sets.newHashSet(); for (String line : lines) { if (isBlank(line)) { continue; }//from ww w .java2s . com Iterator<String> fields = splitter.split(line).iterator(); String x = fields.next(); String y = fields.next(); result.add(Pair.of(x, y)); } return result; }
From source file:jp.mamesoft.mailsocketchat.Mailsocketchat.java
static void Logperse(JSONObject jsondata) { if (!jsondata.isNull("comment")) { String name = jsondata.getString("name"); String comment = jsondata.getString("comment"); String ip = jsondata.getString("ip"); String time_js = jsondata.getString("time"); Pattern time_p = Pattern.compile("([0-9]{4}).([0-9]{2}).([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})"); Matcher time_m = time_p.matcher(time_js); String time = ""; String simpletime = ""; if (time_m.find()) { int year = Integer.parseInt(time_m.group(1)); int month = Integer.parseInt(time_m.group(2)); int day = Integer.parseInt(time_m.group(3)); int hour = Integer.parseInt(time_m.group(4)); int min = Integer.parseInt(time_m.group(5)); int sec = Integer.parseInt(time_m.group(6)); hour = hour + 9;//from ww w .ja va 2s .c o m if (hour >= 24) { hour = hour - 24; day = day + 1; } time = String.format("%1$04d", year) + "-" + String.format("%1$02d", month) + "-" + String.format("%1$02d", day) + " " + String.format("%1$02d", hour) + ":" + String.format("%1$02d", min) + ":" + String.format("%1$02d", sec); simpletime = String.format("%1$02d", hour) + ":" + String.format("%1$02d", min) + ":" + String.format("%1$02d", sec); } String channel = ""; HashMap<String, String> log = new HashMap<String, String>(); log.put("name", name); log.put("_id", jsondata.getString("_id")); log.put("comment", comment); log.put("ip", ip); log.put("time", time); log.put("simpletime", simpletime); if (!jsondata.isNull("response")) { log.put("res", jsondata.getString("response")); } else { log.put("res", ""); } if (!jsondata.isNull("channel")) { HashSet<String> channels_hash = new HashSet<String>(); for (int i = 0; i < jsondata.getJSONArray("channel").length(); i++) { channels_hash.add(jsondata.getJSONArray("channel").getString(i)); } String channels[] = (String[]) channels_hash.toArray(new String[0]); for (int i = 0; i < channels.length; i++) { channel = channel + " #" + channels[i]; } log.put("channel", channel); } if (push) { logs.add(log); Mail.Send(address, 1); } else { logs.add(log); } } }
From source file:com.uwsoft.editor.utils.runtime.EntityUtils.java
public static HashSet<Entity> getByUniqueId(Array<Integer> ids) { HashSet<Entity> entities = new HashSet<>(); for (Integer id : ids) { Entity entity = Sandbox.getInstance().getSceneControl().sceneLoader.entityFactory .getEntityByUniqueId(id); entities.add(entity); }/*from www.ja v a 2s . c o m*/ return entities; }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.Test.java
private static ArrayList<HashSet<String>> extractEntities(File csvData, int nOfAttributes) throws IOException { CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180); int r = 0;/* ww w .j a v a2 s . co m*/ ArrayList<Integer> attributePositions = new ArrayList<>(); ArrayList<String> attributeNames = new ArrayList<>(); ArrayList<HashSet<String>> res = new ArrayList<>(); for (CSVRecord csvRecord : parser) { if (r == 0) { Iterator<String> it = csvRecord.iterator(); it.next(); //skip URI if (!it.hasNext()) { //it is an empty file return res; } it.next(); //skip rdf-schema#label it.next(); //skip rdf-schema#comment int c = 2; for (; it.hasNext();) { c++; String attr = it.next(); if (!attr.endsWith("_label")) { attributePositions.add(c); } } } else if (r == 1) { Iterator<String> it = csvRecord.iterator(); it.next(); //skip uri it.next(); //skip rdf-schema#label it.next(); //skip rdf-schema#comment int c = 2; int i = 0; while (i < attributePositions.size()) { c++; String attr = it.next(); if (attributePositions.get(i) == c) { if (!stopAttributes.contains(attr)) { attributes.add(attr); } attributeNames.add(attr); i++; } } } else if (r > 3) { ArrayList<String> attributesOfThisEntity = new ArrayList<>(); Iterator<String> it = csvRecord.iterator(); String uri = it.next(); it.next(); //skip rdf-schema#label it.next(); //skip rdf-schema#comment int c = 2; int i = 0; while (i < attributePositions.size()) { c++; String val = it.next(); if (attributePositions.get(i) == c) { if (!val.equalsIgnoreCase("null")) { String attribute = attributeNames.get(i); if (!stopAttributes.contains(attribute)) { attributesOfThisEntity.add(attribute); } } i++; } } Collections.shuffle(attributesOfThisEntity); HashSet<String> s = new HashSet<>(); for (int k = 0; k < Math.min(nOfAttributes, attributesOfThisEntity.size()); k++) { s.add(attributesOfThisEntity.get(k)); } res.add(s); } r++; } return res; }