List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:com.microsoft.azure.hdinsight.projects.SbtProjectGenerator.java
private void importSbtProject(String root) { Project project = this.module.getProject(); ExternalSystemUtil.refreshProject(project, SbtProjectSystem.Id(), root, false, ProgressExecutionMode.IN_BACKGROUND_ASYNC); SbtProjectSettings sbtProjectSettings = new SbtProjectSettings(); sbtProjectSettings.setExternalProjectPath(root); SbtSystemSettings sbtSystemSettings = SbtSystemSettings.getInstance(project); HashSet<SbtProjectSettings> projects = ContainerUtilRt .newHashSet(sbtSystemSettings.getLinkedProjectsSettings()); projects.add(sbtProjectSettings); sbtSystemSettings.setLinkedProjectsSettings(projects); }
From source file:com.thoughtworks.go.plugin.configrepo.contract.CREnvironment.java
public String validateNameUniqueness(HashSet<String> keys) { if (keys.contains(this.getName())) return String.format("Environment %s is defined more than once", this.getName()); else//w w w. ja v a 2 s . com keys.add(this.getName()); return null; }
From source file:de.flapdoodle.embed.redis.RedisDProcess.java
protected Set<String> knownFailureMessages() { HashSet<String> ret = new HashSet<String>(); ret.add("failed errno"); ret.add("ERROR:"); return ret;/* w w w. j av a 2 s . c om*/ }
From source file:it.acubelab.smaph.SmaphAnnotator.java
/** * Concatenates the bolds passed by argument. * //from w w w . java2 s . co m * @param bolds * @return the list of concatenated bolds and the set of their mentions. */ private static Pair<String, HashSet<Mention>> concatenateBolds(List<String> bolds) { HashSet<Mention> mentions = new HashSet<Mention>(); String concat = ""; for (String spot : bolds) { int mentionStart = concat.length(); int mentionEnd = mentionStart + spot.length() - 1; mentions.add(new Mention(mentionStart, mentionEnd - mentionStart + 1)); concat += spot + " "; } return new Pair<String, HashSet<Mention>>(concat, mentions); }
From source file:org.openbaton.vim_impl.vim.test.VimTestSuiteClass.java
private VirtualDeploymentUnit createVDU() { VirtualDeploymentUnit vdu = new VirtualDeploymentUnit(); VimInstance vimInstance = createVIM(); HashSet<VNFComponent> vnfc = new HashSet<>(); vnfc.add(new VNFComponent()); vdu.setVnfc(vnfc);//from w w w.j a v a 2s .c o m Set<String> monitoring_parameter = new HashSet<>(); monitoring_parameter.add("parameter_1"); monitoring_parameter.add("parameter_2"); monitoring_parameter.add("parameter_3"); vdu.setMonitoring_parameter(monitoring_parameter); vdu.setComputation_requirement("computation_requirement"); Set<String> vm_images = new HashSet<>(); vm_images.add("image_1234"); vdu.setVm_image(vm_images); vimInstance.setFlavours(new HashSet<DeploymentFlavour>()); DeploymentFlavour deploymentFlavour = new DeploymentFlavour(); deploymentFlavour.setExtId("ext_id"); deploymentFlavour.setFlavour_key("m1.small"); vimInstance.getFlavours().add(deploymentFlavour); return vdu; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo.java
public static Map<String, String> getOptions(EditConfigurationVTwo editConfig, String fieldName, WebappDaoFactory wDaoFact) {/*from w ww . j av a 2 s. com*/ if (editConfig == null) { log.error("fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo "); return Collections.EMPTY_MAP; } if (fieldName == null) { log.error("fieldToSelectItemList() must be called with a non-null fieldName"); return Collections.EMPTY_MAP; } FieldVTwo field = editConfig.getField(fieldName); if (field == null) { log.error("no field \"" + fieldName + "\" found from editConfig in SelectListGenerator.getOptions()"); return Collections.EMPTY_MAP; } // now create an empty HashMap to populate and return HashMap<String, String> optionsMap = new LinkedHashMap<String, String>(); // for debugging, keep a count of the number of options populated int optionsCount = 0; FieldVTwo.OptionsType optionsType = field.getOptionsType(); String vclassUri = null; switch (optionsType) { case HARDCODED_LITERALS: // not auto-sorted, and empty values not removed or replaced List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions(); if (hardcodedLiteralOptions == null) { log.error("no literalOptions List found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType HARDCODED_LITERALS specified"); return new HashMap<String, String>(); } for (Object obj : ((Iterable) hardcodedLiteralOptions)) { List<String> literalPair = (List) obj; String value = (String) literalPair.get(0); if (value != null) { // allow empty string as a value String label = (String) literalPair.get(1); if (label != null) { optionsMap.put(value, label); } else { optionsMap.put(value, value); } ++optionsCount; } } break; case LITERALS: List<List<String>> literalOptions = field.getLiteralOptions(); if (literalOptions == null) { log.error("no literalOptions List found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType LITERALS specified"); return new HashMap<String, String>(); } for (Object obj : ((Iterable) literalOptions)) { List<String> literalPair = (List) obj; String value = (String) literalPair.get(0); if (value != null && value.trim().length() > 0) { String label = (String) literalPair.get(1); if (label != null && label.trim().length() > 0) { optionsMap.put(value, label); } else { optionsMap.put(value, value); } ++optionsCount; } } break; case STRINGS_VIA_DATATYPE_PROPERTY: log.debug("processing Field \"" + fieldName + "\" optionType as a datatype property predicateUri in SelectListGenerator.getOptions()"); String dataPropUri = field.getPredicateUri(); if (dataPropUri == null || dataPropUri.equals("")) { log.error("no predicate dataPropUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType STRINGS_VIA_DATATYPE_PROPERTY specified"); } else { /* first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption=null; if ((defaultOption=getDefaultOption(field))!=null) { optionsMap.put(LEFT_BLANK, defaultOption); } */ // now populate the options log.debug("finding all choices for data property \"" + dataPropUri + "\" in SelectListGenerator.getOptions()"); if (wDaoFact == null) log.error( "incoming WebappDaoFactory from request is null in SelectListGenerator.getOptions()."); DataPropertyStatementDao dpsDao = wDaoFact.getDataPropertyStatementDao(); DataPropertyDao dpDao = wDaoFact.getDataPropertyDao(); DataProperty dp = dpDao.getDataPropertyByURI(dataPropUri); for (Iterator<DataPropertyStatement> i = dpsDao.getDataPropertyStatements(dp).iterator(); i .hasNext();) { DataPropertyStatement dps = i.next(); if (dps != null) { optionsMap.put(dps.getData().trim(), dps.getData().trim()); ++optionsCount; } } } break; case INDIVIDUALS_VIA_OBJECT_PROPERTY: log.debug("processing Field \"" + fieldName + "\" optionType as an object property predicateUri in SelectListGenerator.getOptions()"); String subjectUri = editConfig.getSubjectUri(); if (subjectUri == null || subjectUri.equals("")) { log.error("no subjectUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified"); } else { String predicateUri = field.getPredicateUri(); if (predicateUri == null || predicateUri.equals("")) { log.error("no predicateUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options log.debug("finding range individuals for subject \"" + subjectUri + "\" and object property \"" + predicateUri + "\" in SelectListGenerator.getOptions()"); if (wDaoFact == null) log.error( "could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri); if (subject == null) log.error("could not get individual for subject uri " + subjectUri + " in SelectListGenerator.getOptions()"); ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri); if (objProp == null) log.error("could not get object property for predicate " + predicateUri + " in SelectListGenerator.getOptions()"); List<VClass> vclasses = new ArrayList<VClass>(); vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(), predicateUri); if (vclasses == null) { log.error("no owl:Class found for predicate " + predicateUri); break; } if (vclasses.size() == 0) log.error("no owl:Class found for predicate " + predicateUri); List<Individual> individuals = new ArrayList<Individual>(); HashSet<String> uriSet = new HashSet<String>(); long startTime = System.currentTimeMillis(); for (VClass vclass : vclasses) { for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1)) { if (!uriSet.contains(ind.getURI())) { uriSet.add(ind.getURI()); individuals.add(ind); } } } List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements(); if (stmts == null) log.error("object properties for subject were null in SelectListGenerator.getOptions()"); individuals = removeIndividualsAlreadyInRange(individuals, stmts, predicateUri, editConfig.getObject()); //Collections.sort(individuals,new compareIndividualsByName()); for (Individual ind : individuals) { String uri = ind.getURI(); if (uri != null) { optionsMap.put(uri, ind.getName().trim()); ++optionsCount; } } } } break; case INDIVIDUALS_VIA_VCLASS: //so we have a vclass URI vclassUri = field.getObjectClassUri(); if (vclassUri == null || vclassUri.equals("")) { log.error("no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_VCLASS specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); // if reasoning isn't available, we will also need to add // individuals asserted in subclasses boolean inferenceAvailable = false; if (wDaoFact instanceof WebappDaoFactoryJena) { PelletListener pl = ((WebappDaoFactoryJena) wDaoFact).getPelletListener(); if (pl != null && pl.isConsistent() && !pl.isInErrorState() && !pl.isReasoning()) { inferenceAvailable = true; } } VClass vclass = wDaoFact.getVClassDao().getVClassByURI(vclassUri); if (vclass == null) { log.error("Cannot find owl:Class " + vclassUri + " in the model"); optionsMap.put("", "Could not find class " + vclassUri); } else { Map<String, Individual> individualMap = new HashMap<String, Individual>(); for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } if (!inferenceAvailable) { for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI, -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } } } List<Individual> individuals = new ArrayList<Individual>(); individuals.addAll(individualMap.values()); Collections.sort(individuals); for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } if (!inferenceAvailable) { for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI, -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } } } individuals.addAll(individualMap.values()); Collections.sort(individuals); if (individuals.size() == 0) { log.error("No individuals of type " + vclass.getName() + " to add to pick list in SelectListGenerator.getOptions()"); optionsMap.put("", "No " + vclass.getName() + " found"); } else { for (Individual ind : individuals) { String uri = ind.getURI(); if (uri != null) { optionsMap.put(uri, ind.getName().trim()); ++optionsCount; } } } } } break; case CHILD_VCLASSES: //so we have a vclass URI vclassUri = field.getObjectClassUri(); if (vclassUri == null || vclassUri.equals("")) { log.error("no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); VClassDao vclassDao = wDaoFact.getVClassDao(); List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri); if (subClassList == null || subClassList.size() == 0) { log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used"); } else { for (String subClassUri : subClassList) { VClass subClass = vclassDao.getVClassByURI(subClassUri); if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { optionsMap.put(subClassUri, subClass.getName().trim()); ++optionsCount; } } } } break; case CHILD_VCLASSES_WITH_PARENT: //so we have a vclass URI vclassUri = field.getObjectClassUri(); if (vclassUri == null || vclassUri.equals("")) { log.error("no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); VClassDao vclassDao = wDaoFact.getVClassDao(); List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri); if (subClassList == null || subClassList.size() == 0) { log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used"); } else { for (String subClassUri : subClassList) { VClass subClass = vclassDao.getVClassByURI(subClassUri); if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { optionsMap.put(subClassUri, subClass.getName().trim()); ++optionsCount; } } optionsMap.put(vclassUri, "Other"); ++optionsCount; } } break; case VCLASSGROUP: String classGroupUri = field.getObjectClassUri(); // we're overloading this property to specify the classgroup if (classGroupUri == null || classGroupUri.equals("")) { log.error("no classGroupUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType VCLASSGROUP specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); VClassGroupDao vcgd = wDaoFact.getVClassGroupDao(); // Need to call this method to populate the classgroups - otherwise the classgroup class list is empty List vClassGroups = vcgd.getPublicGroupsWithVClasses(); if (vClassGroups == null) { log.error( "No class groups found, so only default value from field's literalOptions will be used."); } else { VClassGroup vClassGroup = null; for (Object o : vClassGroups) { VClassGroup vcg = (VClassGroup) o; if (vcg.getURI().equals(classGroupUri)) { vClassGroup = vcg; break; } } if (vClassGroup == null) { log.error("No class group with uri " + classGroupUri + "found, so only default value from field's literalOptions will be used."); } else { List<VClass> vClassList = vClassGroup.getVitroClassList(); if (vClassList == null || vClassList.size() == 0) { log.debug("No classes in class group " + classGroupUri + " found in the model, so only default value from field's literalOptions will be used"); } else { for (VClass vClass : vClassList) { String vClassUri = vClass.getURI(); if (vClass != null && !OWL.Nothing.getURI().equals(vClassUri)) { optionsMap.put(vClassUri, vClass.getName().trim()); ++optionsCount; } } } } } } break; case UNDEFINED: log.error("optionsType \"UNDEFINED\" for Field \"" + fieldName + "\" in SelectListGenerator.getOptions()"); break; default: log.error("unknown optionsType " + optionsType.toString() + " for Field \"" + fieldName + "\" in SelectListGenerator.getOptions()"); } log.debug("added " + optionsCount + " options for field \"" + fieldName + "\" in SelectListGenerator.getOptions()"); return optionsMap; }
From source file:com.catify.processengine.core.data.services.ProcessInstanceMediatorServiceTest.java
@Test public void testGetPreviousLoosingNodeIds() { HashSet<String> flowNodeIds = new HashSet<String>(); String flowNodeId = "flowNodeId"; flowNodeIds.add(flowNodeId); when(flowNodeInstanceRepositoryService.findLoosingFlowNodeIds("uniqueProcessId", "uniqueFlowNodeId", "testInstanceId", 0)).thenReturn(flowNodeIds); assertEquals(flowNodeIds, processInstanceMediatorServiceMockInjected .getPreviousLoosingNodeIds("uniqueProcessId", "uniqueFlowNodeId", "testInstanceId")); }
From source file:com.tk.httpClientErp.wsHeadCheck.WsHeadCheckList.java
/** * json,in_time //from w w w.j av a 2s .co m * @return */ private List<HashMap<String, Object>> classification(List<HashMap<String, Object>> jsontoList) { boolean initCompare = true; //true HashMap<String, Object> compareContainer = null; // List<HashMap<String, Object>> fenzuList = new ArrayList<HashMap<String, Object>>(); // if (jsontoList.size() == 0) return fenzuList; // HashSet<String> gd_no = new HashSet<String>(); for (HashMap<String, Object> bean : jsontoList) { gd_no.add(bean.get("gd_no").toString()); } //in_time for (String gdstr : gd_no) { compareContainer = new HashMap<String, Object>(); for (HashMap<String, Object> bean : jsontoList) { if (gdstr.equals(bean.get("gd_no").toString()) && initCompare) { compareContainer = bean; initCompare = false; } else if (gdstr.equals(bean.get("gd_no").toString()) && compareTime(bean.get("in_time").toString(), compareContainer.get("in_time").toString())) { compareContainer = bean; } } fenzuList.add(compareContainer); initCompare = true; } return fenzuList; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java
public static Map<String, String> getOptions(EditConfiguration editConfig, String fieldName, WebappDaoFactory wDaoFact) {/*w w w .j a va 2s. c om*/ if (editConfig == null) { log.error("fieldToSelectItemList() must be called with a non-null EditConfiguration "); return Collections.EMPTY_MAP; } if (fieldName == null) { log.error("fieldToSelectItemList() must be called with a non-null fieldName"); return Collections.EMPTY_MAP; } Field field = editConfig.getField(fieldName); if (field == null) { log.error("no field \"" + fieldName + "\" found from editConfig in SelectListGenerator.getOptions()"); return Collections.EMPTY_MAP; } // now create an empty HashMap to populate and return HashMap<String, String> optionsMap = new LinkedHashMap<String, String>(); // for debugging, keep a count of the number of options populated int optionsCount = 0; Field.OptionsType optionsType = field.getOptionsType(); String vclassUri = null; switch (optionsType) { case HARDCODED_LITERALS: // not auto-sorted, and empty values not removed or replaced List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions(); if (hardcodedLiteralOptions == null) { log.error("no literalOptions List found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType HARDCODED_LITERALS specified"); return new HashMap<String, String>(); } for (Object obj : ((Iterable) hardcodedLiteralOptions)) { List<String> literalPair = (List) obj; String value = (String) literalPair.get(0); if (value != null) { // allow empty string as a value String label = (String) literalPair.get(1); if (label != null) { optionsMap.put(value, label); } else { optionsMap.put(value, value); } ++optionsCount; } } break; case LITERALS: List<List<String>> literalOptions = field.getLiteralOptions(); if (literalOptions == null) { log.error("no literalOptions List found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType LITERALS specified"); return new HashMap<String, String>(); } for (Object obj : ((Iterable) literalOptions)) { List<String> literalPair = (List) obj; String value = (String) literalPair.get(0); if (value != null && value.trim().length() > 0) { String label = (String) literalPair.get(1); if (label != null && label.trim().length() > 0) { optionsMap.put(value, label); } else { optionsMap.put(value, value); } ++optionsCount; } } break; case STRINGS_VIA_DATATYPE_PROPERTY: log.debug("processing Field \"" + fieldName + "\" optionType as a datatype property predicateUri in SelectListGenerator.getOptions()"); String dataPropUri = field.getPredicateUri(); if (dataPropUri == null || dataPropUri.equals("")) { log.error("no predicate dataPropUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType STRINGS_VIA_DATATYPE_PROPERTY specified"); } else { /* first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption=null; if ((defaultOption=getDefaultOption(field))!=null) { optionsMap.put(LEFT_BLANK, defaultOption); } */ // now populate the options log.debug("finding all choices for data property \"" + dataPropUri + "\" in SelectListGenerator.getOptions()"); if (wDaoFact == null) log.error( "incoming WebappDaoFactory from request is null in SelectListGenerator.getOptions()."); DataPropertyStatementDao dpsDao = wDaoFact.getDataPropertyStatementDao(); DataPropertyDao dpDao = wDaoFact.getDataPropertyDao(); DataProperty dp = dpDao.getDataPropertyByURI(dataPropUri); for (Iterator<DataPropertyStatement> i = dpsDao.getDataPropertyStatements(dp).iterator(); i .hasNext();) { DataPropertyStatement dps = i.next(); if (dps != null) { optionsMap.put(dps.getData().trim(), dps.getData().trim()); ++optionsCount; } } } break; case INDIVIDUALS_VIA_OBJECT_PROPERTY: log.debug("processing Field \"" + fieldName + "\" optionType as an object property predicateUri in SelectListGenerator.getOptions()"); String subjectUri = editConfig.getSubjectUri(); if (subjectUri == null || subjectUri.equals("")) { log.error("no subjectUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified"); } else { String predicateUri = field.getPredicateUri(); if (predicateUri == null || predicateUri.equals("")) { log.error("no predicateUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options log.debug("finding range individuals for subject \"" + subjectUri + "\" and object property \"" + predicateUri + "\" in SelectListGenerator.getOptions()"); if (wDaoFact == null) log.error( "could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri); if (subject == null) log.error("could not get individual for subject uri " + subjectUri + " in SelectListGenerator.getOptions()"); ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri); if (objProp == null) log.error("could not get object property for predicate " + predicateUri + " in SelectListGenerator.getOptions()"); List<VClass> vclasses = new ArrayList<VClass>(); vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(), predicateUri); if (vclasses == null) { log.error("no owl:Class found for predicate " + predicateUri); break; } if (vclasses.size() == 0) log.error("no owl:Class found for predicate " + predicateUri); List<Individual> individuals = new ArrayList<Individual>(); HashSet<String> uriSet = new HashSet<String>(); long startTime = System.currentTimeMillis(); for (VClass vclass : vclasses) { for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1)) { if (!uriSet.contains(ind.getURI())) { uriSet.add(ind.getURI()); individuals.add(ind); } } } List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements(); if (stmts == null) log.error("object properties for subject were null in SelectListGenerator.getOptions()"); individuals = removeIndividualsAlreadyInRange(individuals, stmts, predicateUri, editConfig.getObject()); //Collections.sort(individuals,new compareIndividualsByName()); for (Individual ind : individuals) { String uri = ind.getURI(); if (uri != null) { optionsMap.put(uri, ind.getName().trim()); ++optionsCount; } } } } break; case INDIVIDUALS_VIA_VCLASS: //so we have a vclass URI vclassUri = field.getObjectClassUri(); if (vclassUri == null || vclassUri.equals("")) { log.error("no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_VCLASS specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); // if reasoning isn't available, we will also need to add // individuals asserted in subclasses boolean inferenceAvailable = false; if (wDaoFact instanceof WebappDaoFactoryJena) { PelletListener pl = ((WebappDaoFactoryJena) wDaoFact).getPelletListener(); if (pl != null && pl.isConsistent() && !pl.isInErrorState() && !pl.isReasoning()) { inferenceAvailable = true; } } VClass vclass = wDaoFact.getVClassDao().getVClassByURI(vclassUri); if (vclass == null) { log.error("Cannot find owl:Class " + vclassUri + " in the model"); optionsMap.put("", "Could not find class " + vclassUri); } else { Map<String, Individual> individualMap = new HashMap<String, Individual>(); for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } if (!inferenceAvailable) { for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI, -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } } } List<Individual> individuals = new ArrayList<Individual>(); individuals.addAll(individualMap.values()); Collections.sort(individuals); for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } if (!inferenceAvailable) { for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI, -1, -1)) { if (ind.getURI() != null) { individualMap.put(ind.getURI(), ind); } } } } individuals.addAll(individualMap.values()); Collections.sort(individuals); if (individuals.size() == 0) { log.error("No individuals of type " + vclass.getName() + " to add to pick list in SelectListGenerator.getOptions()"); optionsMap.put("", "No " + vclass.getName() + " found"); } else { for (Individual ind : individuals) { String uri = ind.getURI(); if (uri != null) { optionsMap.put(uri, ind.getName().trim()); ++optionsCount; } } } } } break; case CHILD_VCLASSES: //so we have a vclass URI vclassUri = field.getObjectClassUri(); if (vclassUri == null || vclassUri.equals("")) { log.error("no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); VClassDao vclassDao = wDaoFact.getVClassDao(); List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri); if (subClassList == null || subClassList.size() == 0) { log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used"); } else { for (String subClassUri : subClassList) { VClass subClass = vclassDao.getVClassByURI(subClassUri); if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { optionsMap.put(subClassUri, subClass.getName().trim()); ++optionsCount; } } } } break; case CHILD_VCLASSES_WITH_PARENT: //so we have a vclass URI vclassUri = field.getObjectClassUri(); if (vclassUri == null || vclassUri.equals("")) { log.error("no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); VClassDao vclassDao = wDaoFact.getVClassDao(); List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri); if (subClassList == null || subClassList.size() == 0) { log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used"); } else { for (String subClassUri : subClassList) { VClass subClass = vclassDao.getVClassByURI(subClassUri); if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { optionsMap.put(subClassUri, subClass.getName().trim()); ++optionsCount; } } optionsMap.put(vclassUri, "Other"); ++optionsCount; } } break; case VCLASSGROUP: String classGroupUri = field.getObjectClassUri(); // we're overloading this property to specify the classgroup if (classGroupUri == null || classGroupUri.equals("")) { log.error("no classGroupUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType VCLASSGROUP specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal options String defaultOption = null; if ((defaultOption = getDefaultOption(field)) != null) { optionsMap.put(LEFT_BLANK, defaultOption); } // now populate the options if (wDaoFact == null) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); VClassGroupDao vcgd = wDaoFact.getVClassGroupDao(); // Need to call this method to populate the classgroups - otherwise the classgroup class list is empty List vClassGroups = vcgd.getPublicGroupsWithVClasses(); if (vClassGroups == null) { log.error( "No class groups found, so only default value from field's literalOptions will be used."); } else { VClassGroup vClassGroup = null; for (Object o : vClassGroups) { VClassGroup vcg = (VClassGroup) o; if (vcg.getURI().equals(classGroupUri)) { vClassGroup = vcg; break; } } if (vClassGroup == null) { log.error("No class group with uri " + classGroupUri + "found, so only default value from field's literalOptions will be used."); } else { List<VClass> vClassList = vClassGroup.getVitroClassList(); if (vClassList == null || vClassList.size() == 0) { log.debug("No classes in class group " + classGroupUri + " found in the model, so only default value from field's literalOptions will be used"); } else { for (VClass vClass : vClassList) { String vClassUri = vClass.getURI(); if (vClass != null && !OWL.Nothing.getURI().equals(vClassUri)) { optionsMap.put(vClassUri, vClass.getName().trim()); ++optionsCount; } } } } } } break; case UNDEFINED: log.error("optionsType \"UNDEFINED\" for Field \"" + fieldName + "\" in SelectListGenerator.getOptions()"); break; default: log.error("unknown optionsType " + optionsType.toString() + " for Field \"" + fieldName + "\" in SelectListGenerator.getOptions()"); } log.debug("added " + optionsCount + " options for field \"" + fieldName + "\" in SelectListGenerator.getOptions()"); return optionsMap; }
From source file:OpenCalaisGenerateRdfPropertiesFromWebPages.java
private void spider(String starting_url, int spider_depth) throws Exception { System.out.println("** spider(" + starting_url + ", " + spider_depth + ")"); WebSpider ws = new WebSpider(starting_url, spider_depth); Map<String, Set<String>> for_shared_properties = new HashMap<String, Set<String>>(); for (List<String> ls : ws.url_content_lists) { String url = ls.get(0);//from ww w . ja v a 2s. co m String text = ls.get(1); System.out.println("\n\n\n----URL:\n" + url + "\n content:\n" + text); if (text.length() > 120) { Map<String, List<String>> results = new OpenCalaisClient().getPropertyNamesAndValues(text); out.println("<" + url + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://knowledgebooks.com/rdf/webpage> ."); out.println("<" + url + "> <http://knowledgebooks.com/rdf/contents> \"" + text.replaceAll("\"", "'") + "\" ."); if (results.get("Person") != null) for (String person : results.get("Person")) { out.println("<" + url + "> <http://knowledgebooks.com/rdf/containsPerson> \"" + person.replaceAll("\"", "'") + "\" ."); } for (String key : results.keySet()) { System.out.println(" " + key + ": " + results.get(key)); for (Object val : results.get(key)) { String property = "<http://knowledgebooks.com/rdf/" + key + ">"; if (("" + val).length() > 0) { out.println( "<" + url + "> <http://knowledgebooks.com/rdf/" + key + "> \"" + val + "\" ."); HashSet<String> hs = (HashSet<String>) for_shared_properties.get(property); if (hs == null) hs = new HashSet<String>(); hs.add("\"" + val + "\""); for_shared_properties.put("<http://knowledgebooks.com/rdf/" + key + ">", hs); } } } } interpage_shared_properties.put(url, for_shared_properties); } process_interpage_shared_properties(); }