@Override public String getName() { NodeIterator ni; try { ni = KBObjectImpl.getBaseContextModel().listObjectsOfProperty( ((Individual)((VariableImpl)this).getCore()), (OntProperty)((KBPredicateImpl)Constants.getInstance().RIF_VARNAME_PRED).getCore()); if (ni.hasNext()) { return ni.next().asLiteral().getString(); } } catch (Exception ex) { Logger.getLogger(VariableImpl.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
/** * Finds all RTM_IN_SCOPE properties for this property and returns a * collection containing the RDF URIs of the values as URILocators. */ private Collection getScope(RDFNode rdfprop, Model model) throws JenaException, MalformedURLException { Resource subject = (Resource) rdfprop; Property prop = model.getProperty(RTM_IN_SCOPE); NodeIterator it = model.listObjectsOfProperty(subject, prop); ArrayList scope = new ArrayList(); while (it.hasNext()) { Object o = it.next(); if (!(o instanceof Resource)) throw new RDFMappingException("Scoping topic must be specified by a resource, not by " + o); Resource obj = (Resource) o; LocatorIF loc = new URILocator(obj.getURI()); scope.add(loc); } return scope; }
private TopicIF getType(RDFNode rdfprop, Model model) throws JenaException, MalformedURLException { Resource subject = (Resource) rdfprop; Property prop = model.getProperty(RTM_TYPE); NodeIterator it = model.listObjectsOfProperty(subject, prop); while (it.hasNext()) { Resource obj = (Resource) it.next(); LocatorIF loc = new URILocator(obj.getURI()); TopicIF topic = topicmap.getTopicBySubjectIdentifier(loc); if (topic == null) { topic = builder.makeTopic(); topic.addSubjectIdentifier(loc); } return topic; } return null; }
private List<Resource> createSubjectMaps(Resource mappingResource, KR2RMLMapping kr2rmlMapping) throws JSONException { List<Resource> subjectMapResources = new ArrayList<Resource>(); Property hasTrMapUri = model.getProperty(Uris.KM_HAS_TRIPLES_MAP_URI); // Get all the triple maps NodeIterator trMapsResItr = model.listObjectsOfProperty(mappingResource, hasTrMapUri); while (trMapsResItr.hasNext()) { Resource trMapRes = trMapsResItr.next().asResource(); SubjectMap subjMap = addSubjectMapForTripleMap(trMapRes, kr2rmlMapping, subjectMapResources); // Add the Triples map TriplesMap trMap = new TriplesMap(trMapRes.getURI(), subjMap); kr2rmlMapping.getTriplesMapIndex().put(trMapRes.getURI(), trMap); kr2rmlMapping.addTriplesMap(trMap); kr2rmlMapping.getAuxInfo().getTriplesMapGraph().addTriplesMap(trMap); } return subjectMapResources; }
private List<String> getVariables(Model model, Resource service_resource) { Property has_variable_property = model.getProperty(Namespaces.KARMA + "hasVariable"); List<String> variables = new ArrayList<String>(); NodeIterator nodeIterator = null; RDFNode node = null; // hasAttribute nodeIterator = model.listObjectsOfProperty(service_resource, has_variable_property); while ( nodeIterator.hasNext()) { node = nodeIterator.next(); if (!node.isResource()) { logger.info("object of the hasAttribute property is not a resource."); continue; } variables.add(node.asResource().getLocalName()); } return variables; }
@Test public void test_buildTblToTM_1() { Model r2rml = readR2RML(r2rml1); R2RMLSpec spec = new R2RMLSpec(r2rml); Resource expectedTMSubject = ResourceFactory.createResource(prefix + "TriplesMap1"); NodeIterator tmpRes = r2rml.listObjectsOfProperty(expectedTMSubject, RR.logicalTable); Resource expectedTblSubject = tmpRes.next().asResource(); LogicalTable logTbl = new LogicalTable(r2rml, expectedTblSubject); Pair<LogicalTable, TriplesMap> expectedLtTm = new Pair<LogicalTable, TriplesMap>( logTbl, new TriplesMap(r2rml, expectedTMSubject)); int expectedNumLtTmEntries = 1; Map<LogicalTable, Collection<TriplesMap>> tableToTMs = R2RML2SMLConverter.buildTblToTM(spec); assertEquals(expectedNumLtTmEntries, tableToTMs.size()); assertEquals(expectedNumLtTmEntries, tableToTMs.keySet().size()); Set<LogicalTable> tbls = tableToTMs.keySet(); assertTrue(tbls.contains(expectedLtTm.first)); Collection<TriplesMap> triplesMaps = tableToTMs.get(logTbl); assertTrue(triplesMaps.contains(expectedLtTm.second)); }
@Test public void generateQuadQualityProblem(){ qr = new QualityReport(); String qualityProblemURI = qr.createQualityProblem(metricURI, quadProblemList); Model qualityProblem = qr.getProblemReportFromTBD(qualityProblemURI); // checks if model contains appropriate data assertEquals(14, qualityProblem.size()); assertTrue(qualityProblem.listStatements(null, RDF.type, QPRO.QualityProblem).hasNext()); assertTrue(qualityProblem.listStatements(null, QPRO.isDescribedBy, metricURI).hasNext()); NodeIterator objects = qualityProblem.listObjectsOfProperty(QPRO.problematicThing); assertTrue(objects.hasNext()); RDFNode _node = objects.next(); assertTrue(_node.asNode().isBlank()); assertTrue(qualityProblem.listStatements(_node.asResource(), RDF.type, RDF.Statement).hasNext()); assertTrue(qualityProblem.listStatements(_node.asResource(), RDF.subject, (RDFNode) null).hasNext()); assertTrue(qualityProblem.listStatements(_node.asResource(), RDF.predicate, RDFS.label).hasNext()); assertTrue(qualityProblem.listStatements(_node.asResource(), RDF.object, (RDFNode) null).hasNext()); qr.flush(); }
public NetworkingAdapter(Model adapterModel, Resource adapterABox) { this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; this.adapterABox = adapterABox; Resource adapterType =getAdapterClass(); this.adapterABox.addProperty(RDF.type,adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "A networking adapter that can create virtual link among resources."); NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); ResIterator propertiesIterator = adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propertiesIterator.hasNext()) { Property p = adapterTBox.getProperty(propertiesIterator.next().getURI()); networkingControlProperties.add(p); } } }
@Override public Model createInstances(Model model) throws ProcessingException, InvalidRequestException { Model createdInstancesModel = super.createInstances(model); LOGGER.warning("createInstances override method."); String topologyUri = null; NodeIterator objects = model.listObjectsOfProperty(Omn.isResourceOf); if (objects.hasNext()) { RDFNode object = objects.next(); topologyUri = object.asResource().getURI(); } return createdInstancesModel; }
@SuppressWarnings("unchecked") public <T> void setValue(T value, Type valueType) { if (_statement != null) { if (valueType instanceof Class<?>) setValue(_statement, value, (Class<T>) valueType); else if (valueType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) valueType; if (parameterizedType.getRawType().equals(List.class) && (parameterizedType.getActualTypeArguments().length == 1)) { Type actualTypeArgument = parameterizedType.getActualTypeArguments()[0]; List<Object> list = new LinkedList<Object>(); NodeIterator bagIterator = _statement.getBag().iterator(); // TODO // while (bagIterator.hasNext()) // setValue(bagIterator.next(), (Class<?>) actualTypeArgument)); } } } }
public static Set<String> getAllTypes(Model model, String typePrefix) { Resource rootResource = model.createResource(typePrefix); com.hp.hpl.jena.rdf.model.Property classProperty = model.createProperty("http://dblab.cs.toronto.edu/project/xcurator/0.1#classes"); Bag classBag = model.createBag("http://dblab.cs.toronto.edu/project/xcurator/0.1#classBag"); model.add(rootResource, classProperty, classBag); Set<String> ret = new HashSet<String>(); NodeIterator iterator = classBag.iterator(); while (iterator.hasNext()) { Resource resource = (Resource) iterator.next(); ret.add(resource.getURI()); } return ret; }
public static boolean checkPrecedence(CompanyModel c) { StmtIterator stmtit = c.getModel().listStatements( new SimpleSelector(null, c.DEPTS, (RDFNode) null)); List<Resource> depts = new LinkedList<Resource>(); while (stmtit.hasNext()) { NodeIterator subDeptsIt = stmtit.next().getBag().iterator(); while (subDeptsIt.hasNext()) depts.add(subDeptsIt.next().asResource()); } for (Resource dept : depts) { // get manager's salary double managerSalary = dept.getProperty(c.MANAGER).getProperty( c.SALARY).getDouble(); NodeIterator employeeIt = dept.getProperty(c.EMPLOYEES).getBag() .iterator(); while (employeeIt.hasNext()) if (!(employeeIt.next().asResource().getProperty(c.SALARY) .getDouble() < managerSalary)) return false; } return true; }
/** * exclude these words when enhancing. * * @param ocls * @param additionalExcludes * @return */ public List<String> getAllExcludes(OntClass ocls, String... additionalExcludes) { List<String> excludeList = new ArrayList<String>(5); AnnotationProperty apExclude = model.getAnnotationProperty(NS + "synExcludes"); //to add synExcludes to list AnnotationProperty apSyn = model.getAnnotationProperty(NS + SynSuggestion.TYPE_SynInclude);// to add slreeady added synIncludes AnnotationProperty apAsso = PO.AP_ASSOCIATON; //add all additionalExcludes if (additionalExcludes != null) { for (int i = 0; i < additionalExcludes.length; i++) { additionalExcludes[i] = additionalExcludes[i].toLowerCase(); } Collections.addAll(excludeList, additionalExcludes); } // add syn excludes NodeIterator itrExcludes = ocls.listPropertyValues(apExclude); while (itrExcludes.hasNext()) { String synExs = itrExcludes.next().asLiteral().getLexicalForm(); String synEx[] = synExs.split(","); for (int i = 0; i < synEx.length; i++) { synEx[i] = synEx[i].trim(); } Collections.addAll(excludeList, synEx); } // add synIncludes NodeIterator itrSyn = ocls.listPropertyValues(apSyn); // add to exclude list, already added synonyms also while (itrSyn.hasNext()) { excludeList.add(itrSyn.next().asLiteral().getLexicalForm()); } //add association NodeIterator itrAsso = ocls.listPropertyValues(apAsso); while (itrAsso.hasNext()) { excludeList.add(itrAsso.next().asLiteral().getLexicalForm()); } logger.debug("exclude list:" + excludeList); return excludeList; }
public List<String> getAssociations() { List<String> associations = associations = new ArrayList<String>(4); AnnotationProperty associationAnn =PO.AP_ASSOCIATON; NodeIterator itrAssociation = f.listPropertyValues(associationAnn); while (itrAssociation.hasNext()) { String asso = itrAssociation.next().asLiteral().getLexicalForm(); associations.add(asso); } return associations; }
private void buildNotesTree( Model model, String parentResourceUri, String notebookUri, ConceptTreeNode parentNode, AnnotationTransformer annotationTransformer) throws Exception { String conceptUri; ConceptResource concept; RDFNode statement; Seq seq = model.getSeq(parentResourceUri); NodeIterator i = seq.iterator(); cat.debug("<-> concept tree builder - got root: " + parentResourceUri); ConceptTreeNode child; while (i.hasNext()) { statement = i.nextNode(); // add children to parent node conceptUri = statement.toString(); cat.debug(" <-> concept tree builder - child '" + conceptUri + "'"); concept = MindRaider.noteCustodian.get(notebookUri, conceptUri); child = new ConceptTreeNode(); // TODO create resource clone to avoid changing of annotations if (annotationTransformer != null) { concept.setAnnotation(annotationTransformer.transform(concept.getAnnotation())); } child.setConcept(concept.resource); parentNode.getChildren().add(child); // now dive recursively for each existing node... buildNotesTree(model, conceptUri, notebookUri, child, annotationTransformer); } }
private LocatorIF getTopicIndicator(Resource subject, String property, Model model) throws JenaException, MalformedURLException { Property prop = model.getProperty(property); NodeIterator it = model.listObjectsOfProperty(subject, prop); while (it.hasNext()) { Resource obj = (Resource) it.next(); if (obj.isAnon()) continue; // FIXME: is this really ok? return new URILocator(obj.getURI()); } return null; }
private Resource getMappingResourceFromSourceName() throws KarmaException { Property sourceNameProp = model.getProperty(Uris.KM_SOURCE_NAME_URI); RDFNode node = model.createLiteral(id.getName()); ResIterator res = model.listResourcesWithProperty(sourceNameProp, node); List<Resource> resList = res.toList(); if (resList.size() > 1) { throw new KarmaException("More than one resource exists with source name: " + id.getName()); } else if (resList.size() == 1) { return resList.get(0); } else { //If we didnt find the sourceName in the model, maybe it is a different source with the //same schema. //Maybe we need to substitute the sourceName in the model with this one NodeIterator sourceObjectIter = model.listObjectsOfProperty(sourceNameProp); List<RDFNode> sourceObjects = sourceObjectIter.toList(); if(sourceObjects.size() > 1) { throw new KarmaException("More than one resource exists with source name: " + id.getName()); } else if(sourceObjects.size() == 1) { RDFNode prevSourceObject = sourceObjects.get(0); //We got the previous source object, now get the Subject Node for this ResIterator prevSourceSubjectsIter = model.listResourcesWithProperty(sourceNameProp, prevSourceObject); List<Resource> prevSourceSubjects = prevSourceSubjectsIter.toList(); if (prevSourceSubjects.size() == 1) { Resource subject = prevSourceSubjects.get(0); model.remove(subject, sourceNameProp, prevSourceObject); model.add(subject, sourceNameProp, node); return subject; } else if(prevSourceSubjects.size() > 1) { throw new KarmaException("More than one resource exists with model source name: " + prevSourceObject.toString()); } } return null; } }
private JSONArray getWorksheetHistory(Resource mappingResource) throws JSONException { Property hasTransformation = model.getProperty(Uris.KM_HAS_WORKSHEET_HISTORY_URI); NodeIterator transItr = model.listObjectsOfProperty(mappingResource, hasTransformation); while (transItr.hasNext()) { String commands = transItr.next().toString(); return new JSONArray(commands); } return new JSONArray(); }
private void createPredicateObjectMaps(Resource mappingResource, KR2RMLMapping kr2rmlMapping) throws JSONException { Property hasTrMapUri = model.getProperty(Uris.KM_HAS_TRIPLES_MAP_URI); // Get all the triple maps NodeIterator trMapsResItr = model.listObjectsOfProperty(mappingResource, hasTrMapUri); while (trMapsResItr.hasNext()) { // Add the predicate object maps addPredicateObjectMapsForTripleMap(trMapsResItr.next().asResource(), kr2rmlMapping); } }
private Atom getAtom(Model model, Resource atom_resource) { Property rdf_type = model.getProperty(Namespaces.RDF + "type"); NodeIterator nodeIterator = null; RDFNode node = null; String classAtomUri = Namespaces.SWRL + "ClassAtom"; String propertyAtomUri = Namespaces.SWRL + "IndividualPropertyAtom"; // atom type nodeIterator = model.listObjectsOfProperty(atom_resource, rdf_type); if (!nodeIterator.hasNext() || !(node = nodeIterator.next()).isResource()) { logger.info("The atom type is not specified."); return null; } if (node.asResource().getURI().equalsIgnoreCase(classAtomUri)) { logger.debug("The atom is a ClassAtom"); return getClassAtom(model, atom_resource); } else if (node.asResource().getURI().equalsIgnoreCase(propertyAtomUri)) { logger.debug("The atom is an IndividualPropertyAtom"); return getPropertyAtom(model, atom_resource); } return null; }
protected static Literal getLiteralObject(final Resource s, final Property p) { final NodeIterator nodes = s.getModel().listObjectsOfProperty(s, p); if (nodes.hasNext()) { final RDFNode node = nodes.next(); if (node.isLiteral()) { return node.asLiteral(); } } return null; }
private void addSuperPropertiesWithoutRange(ModelConcepts concepts, StringBuilder sb, OntResource prop) { if (!hasRange(prop)) { String thisPropString; if (prop.isObjectProperty() || concepts.getPseudoObjProperties().contains(prop)) { thisPropString = objPropertyToSadl(concepts, prop); } else { thisPropString = dtPropertyToSadl(concepts, prop); } if (concepts.getPseudoObjProperties().contains(prop)) { sb.append("// "); sb.append(prop.getLocalName()); sb.append(" is not typed in the input but SADL requires typed properties\n// --typed as object property to match subproperties\n"); } else if (concepts.getPseudoDtProperties().contains(prop)) { sb.append("// "); sb.append(prop.getLocalName()); sb.append(" is not typed in the input but SADL requires typed properties\n// --typed as datatype property to match subproperties\n"); } concepts.addCompleted(prop); NodeIterator nitr2 = prop.listPropertyValues(RDFS.subPropertyOf); if (nitr2.hasNext()) { RDFNode superprop = nitr2.nextNode(); if (superprop.canAs(OntProperty.class)){ OntProperty supProp = superprop.as(OntProperty.class); addSuperPropertiesWithoutRange(concepts, sb, supProp); } } sb.append(thisPropString); } }
private boolean hasRange(OntResource prop) { NodeIterator nitr = prop.listPropertyValues(RDFS.range); if (!nitr.hasNext()) { return false; } else { RDFNode rng = nitr.nextNode(); if (rng.equals(RDFS.Resource)) { // rdfs:Resource is treated (for now?) as not a range as it adds no information and creates a SADL error. return false; } } return true; }
private void addInstancePropertyValue(Individual inst, Property prop, RDFNode value, EObject ctx) { if (prop.getURI().equals(SadlConstants.SADL_IMPLICIT_MODEL_IMPLIED_PROPERTY_URI)) { // check for ambiguity through duplication of property range if (value.canAs(OntProperty.class)) { NodeIterator ipvs = inst.listPropertyValues(prop); if (ipvs.hasNext()) { List<OntResource> valueRngLst = new ArrayList<OntResource>(); ExtendedIterator<? extends OntResource> vitr = value.as(OntProperty.class).listRange(); while (vitr.hasNext()) { valueRngLst.add(vitr.next()); } vitr.close(); boolean overlap = false; while (ipvs.hasNext()) { RDFNode ipv = ipvs.next(); if (ipv.canAs(OntProperty.class)) { ExtendedIterator<? extends OntResource> ipvitr = ipv.as(OntProperty.class).listRange(); while (ipvitr.hasNext()) { OntResource ipvr = ipvitr.next(); if (valueRngLst.contains(ipvr)) { addError("Ambiguous condition--multiple implied properties (" + value.as(OntProperty.class).getLocalName() + "," + ipv.as(OntProperty.class).getLocalName() + ") have the same range (" + ipvr.getLocalName() + ")", ctx); } } } } } } addImpliedPropertyClass(inst); } else if (prop.getURI().equals(SadlConstants.SADL_IMPLICIT_MODEL_EXPANDED_PROPERTY_URI)) { addExpandedPropertyClass(inst); } inst.addProperty(prop, value); logger.debug("added value '" + value.toString() + "' to property '" + prop.toString() + "' for instance '" + inst.toString() + "'"); }
@Test public void hasCategoryDefined(){ this.setQualityGraphURI(); Model _qualityGraph = _dataset.getNamedModel(this.qualityGraphURI.getURI()); assertTrue(_qualityGraph.contains(null, RDF.type, this.categoryResource)); ResIterator iter = _qualityGraph.listSubjectsWithProperty(RDF.type, this.categoryResource); this.categoryURI = iter.next(); NodeIterator iter2 = _qualityGraph.listObjectsOfProperty(m.createProperty(this.dimensionProperty.getURI())); this.dimensionURI = iter2.next().asResource(); assertTrue(_qualityGraph.contains(this.categoryURI, m.createProperty(this.dimensionProperty.getURI()), this.dimensionURI)); }
@Test public void hasDimensionDefined(){ this.setQualityGraphURI(); Model _qualityGraph = _dataset.getNamedModel(this.qualityGraphURI.getURI()); assertTrue(_qualityGraph.contains(this.dimensionURI, RDF.type, this.dimensionResource)); NodeIterator iter2 = _qualityGraph.listObjectsOfProperty(m.createProperty(this.metricProperty.getURI())); this.metricURI = iter2.next().asResource(); assertTrue(_qualityGraph.contains(this.dimensionURI, m.createProperty(this.metricProperty.getURI()) , this.metricURI)); }
@Test public void hasNumberOfObservations(){ this.setQualityGraphURI(); Model _qualityGraph = _dataset.getNamedModel(this.qualityGraphURI.getURI()); NodeIterator iter = _qualityGraph.listObjectsOfProperty(this.metricURI, DAQ.hasObservation); if (this.parameter){ assertEquals(2, iter.toList().size()); } else { assertEquals(1, iter.toList().size()); } }
@Test public void correctObservationStructure(){ this.setQualityGraphURI(); Model _qualityGraph = _dataset.getNamedModel(this.qualityGraphURI.getURI()); NodeIterator iter = _qualityGraph.listObjectsOfProperty(this.metricURI, DAQ.hasObservation); while (iter.hasNext()){ RDFNode node = iter.next(); assertTrue(_qualityGraph.contains(node.asResource(), RDF.type, DAQ.Observation)); assertTrue(_qualityGraph.contains(node.asResource(), DAQ.computedOn, this.computedOn)); assertTrue(_qualityGraph.contains(node.asResource(), SDMXDIMENSION.timePeriod)); assertTrue(_qualityGraph.contains(node.asResource(), DAQ.value)); assertTrue(_qualityGraph.contains(node.asResource(), DAQ.metric, this.metricURI)); assertTrue(_qualityGraph.contains(node.asResource(), CUBE.dataSet, this.qualityGraphURI)); } }
private static List<Observation> extractObservations(Model qualityMD, Resource metric){ List<Observation> lst = new ArrayList<Observation>(); NodeIterator iter = qualityMD.listObjectsOfProperty(metric, DAQ.hasObservation); while(iter.hasNext()){ Resource res = iter.next().asResource(); //get datetime Date date = null; try { date = toDateFormat(qualityMD.listObjectsOfProperty(res, qualityMD.createProperty("http://purl.org/linked-data/sdmx/2009/dimension#timePeriod")).next().asLiteral().getValue().toString()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } //get value Double value = qualityMD.listObjectsOfProperty(res, DAQ.value).next().asLiteral().getDouble(); //get computedOn Resource computedOn = qualityMD.listObjectsOfProperty(res,DAQ.computedOn).next().asResource(); //data cube Resource cubeDS = qualityMD.listObjectsOfProperty(res, CUBE.dataSet).next().asResource(); Observation obs = new Observation(res, date, value, null,computedOn, cubeDS); lst.add(obs); } return lst; }
public static List<Observation> extractObservations(Model qualityMD, Resource metric){ List<Observation> lst = new ArrayList<Observation>(); ResIterator itRes = qualityMD.listResourcesWithProperty(RDF.type, metric); if (!(itRes.hasNext())) return lst; Resource resNode = itRes.next(); NodeIterator iter = qualityMD.listObjectsOfProperty(resNode, DAQ.hasObservation); while(iter.hasNext()){ Resource res = iter.next().asResource(); //get datetime Date date = null; try { date = toDateFormat(qualityMD.listObjectsOfProperty(res, qualityMD.createProperty("http://purl.org/linked-data/sdmx/2009/dimension#timePeriod")).next().asLiteral().getValue().toString()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } //get value Double value = qualityMD.listObjectsOfProperty(res, DAQ.value).next().asLiteral().getDouble(); //get computedOn Resource computedOn = qualityMD.listObjectsOfProperty(res,DAQ.computedOn).next().asResource(); //data cube Resource cubeDS = qualityMD.listObjectsOfProperty(res, CUBE.dataSet).next().asResource(); Observation obs = new Observation(res, date, value, null,computedOn, cubeDS); lst.add(obs); } return lst; }
public AttenuatorAdapter(final Model adapterModel, final Resource adapterABox) { super(); this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; this.attenuator = new Attenuator(); this.attenuator.set_attenuator_url(parseConfig(adapterABox, "attenuator_url")); this.attenuator.set_attenuator_port(parseConfig(adapterABox, "attenuator_port")); this.attenuator.set_attenuator_id(parseConfig(adapterABox, "attenuator_id")); Model model = ModelFactory.createDefaultModel(); Resource adapterInstance = model.createResource(adapterABox.getURI()); this.adapterABox = adapterInstance; final Resource adapterType = this.getAdapterClass(); this.adapterABox.addProperty(RDF.type, adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "Attenuator"); final NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { final Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); final ResIterator propIterator = this.adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propIterator.hasNext()) { final Property property = this.adapterTBox.getProperty(propIterator.next().getURI()); AttenuatorAdapter.ATTENUATOR_CTRL_PROPS.add(property); } } }
public ACSclientAdapter(final Model adapterModel, final Resource adapterABox) { super(); this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; this.url = parseConfig(adapterABox, "url"); this.device = parseConfig(adapterABox, "device"); this.parameterName = parseConfig(adapterABox, "parameter"); Model model = ModelFactory.createDefaultModel(); Resource adapterInstance = model.createResource(adapterABox.getURI()); this.adapterABox = adapterInstance; final Resource adapterType = this.getAdapterClass(); this.adapterABox.addProperty(RDF.type, adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "A client for Auto Configuration Server"); final NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { final Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); final ResIterator propIterator = this.adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propIterator.hasNext()) { final Property property = this.adapterTBox.getProperty(propIterator.next().getURI()); ACSclientAdapter.ACS_CTRL_PROPS.add(property); } } this.parametersList = getDeviceParameters(); System.out.println("PARAMETER SIZE IS " + parametersList.size()); setDefaultParameters(); }
public OpenstackAdapter(Model adapterTBox, Resource adapterABox){ this.uuid = UUID.randomUUID().toString(); this.openstackClient = new OpenstackClient(this); this.adapterTBox = adapterTBox; this.adapterABox = adapterABox; Resource adapterType = Omn_domain_pc.VMServer; this.adapterABox.addProperty(RDF.type,adapterType); // this.adapterABox.addProperty(RDF.type,Omn.Resource); // this.adapterABox.addProperty(RDFS.subClassOf, Omn.); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "Openstack server"); Property longitude = adapterTBox.createProperty("http://www.w3.org/2003/01/geo/wgs84_pos#long"); Property latitude = adapterTBox.createProperty("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); this.adapterABox.addProperty(latitude, "52.516377"); this.adapterABox.addProperty(longitude, "13.323732"); // this.adapterABox.addProperty(Omn_lifecycle.canImplement, Omn_domain_pc.VM); final NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { final Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); final ResIterator propIterator = this.adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propIterator.hasNext()) { final Property property = this.adapterTBox.getProperty(propIterator.next().getURI()); } } }
private String getRequestedDiskImageUri(Resource requestedVM) { NodeIterator stmtIterator = requestedVM.getModel().listObjectsOfProperty(Omn_domain_pc.hasDiskimageLabel); String requestedType = null; while (stmtIterator.hasNext()){ RDFNode statement = stmtIterator.next(); String one = statement.asLiteral().getString(); // boolean isNode = one.equals(Omn_resource.Node); // if(!isNode){ // requestedType = statement.getObject().asResource().getURI(); // break; // } return one; } return null; }
public OpenBatonAdapter(final Model adapterModel, Resource adapterABox) { super(); this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; this.adapterABox = adapterABox; final Resource adapterType = this.getAdapterClass(); this.adapterABox.addProperty(RDF.type, adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "OpenBaton Adapter"); this.adapterABox.addLiteral(MessageBusOntologyModel.maxInstances, 100); // this.adapterABox.addProperty(Omn_lifecycle.canImplement, // Omn_domain_pc.PC); /** * Looking up all Resources that belongs to the Adapter and will be * shown in SFA as Nodes. */ Model implementables = OntologyModelUtil.loadModel("ontologies/openBaton-adapter.ttl", IMessageBus.SERIALIZATION_TURTLE); final NodeIterator resourceIterator = implementables.listObjectsOfProperty(Omn_lifecycle.implements_); while (resourceIterator.hasNext()) { final Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); final ResIterator propIterator = this.adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propIterator.hasNext()) { final Property property = this.adapterTBox.getProperty(propIterator.next().getURI()); } } }
public MotorAdapter(final Model adapterModel, final Resource adapterABox) { super(); this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; this.adapterABox = adapterABox; final Resource adapterType = this.getAdapterClass(); this.adapterABox.addProperty(RDF.type, adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "A motor garage adapter that can simulate different dynamic motor resources."); this.adapterABox.addLiteral(MessageBusOntologyModel.maxInstances, 10); final Property longitude = this.adapterTBox.createProperty("http://www.w3.org/2003/01/geo/wgs84_pos#long"); final Property latitude = this.adapterTBox.createProperty("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); this.adapterABox.addProperty(latitude, "52.516377"); this.adapterABox.addProperty(longitude, "13.323732"); final NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { final Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); final ResIterator propIterator = this.adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propIterator.hasNext()) { final Property property = this.adapterTBox.getProperty(propIterator.next().getURI()); MotorAdapter.MOTOR_CTRL_PROPS.add(property); } } }
public SshServiceAdapter(Model adapterModel, Resource adapterABox) { this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; parseSshParameters(adapterABox); Model model = ModelFactory.createDefaultModel(); Resource adapterInstance = model.createResource(adapterABox.getURI()); this.adapterABox = adapterInstance; Resource adapterType =getAdapterClass(); this.adapterABox.addProperty(RDF.type,adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "A ssh service adapter that can create and manage SSH services to different machines."); NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); ResIterator propertiesIterator = adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propertiesIterator.hasNext()) { Property p = adapterTBox.getProperty(propertiesIterator.next().getURI()); sshServiceControlProperties.add(p); } } }
public EnvironmentSensorAdapter(final Model adapterModel, final Resource adapterABox) { super(); this.uuid = UUID.randomUUID().toString(); this.adapterTBox = adapterModel; this.adapterABox = adapterABox; final Resource adapterType = this.getAdapterClass(); this.adapterABox.addProperty(RDF.type, adapterType); this.adapterABox.addProperty(RDFS.label, this.adapterABox.getLocalName()); this.adapterABox.addProperty(RDFS.comment, "A environmentsensor garage adapter that can simulate different dynamic environmentsensor resources."); this.adapterABox.addLiteral(MessageBusOntologyModel.maxInstances, 10); final Property longitude = this.adapterTBox.createProperty("http://www.w3.org/2003/01/geo/wgs84_pos#long"); final Property latitude = this.adapterTBox.createProperty("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); this.adapterABox.addProperty(latitude, "52.516377"); this.adapterABox.addProperty(longitude, "13.323732"); final NodeIterator resourceIterator = this.adapterTBox.listObjectsOfProperty(Omn_lifecycle.implements_); if (resourceIterator.hasNext()) { final Resource resource = resourceIterator.next().asResource(); this.adapterABox.addProperty(Omn_lifecycle.canImplement, resource); this.adapterABox.getModel().add(resource.getModel()); final ResIterator propIterator = this.adapterTBox.listSubjectsWithProperty(RDFS.domain, resource); while (propIterator.hasNext()) { final Property property = this.adapterTBox.getProperty(propIterator.next().getURI()); EnvironmentSensorAdapter.MOTOR_CTRL_PROPS.add(property); } } }
@SuppressWarnings("unchecked") public <T> T getValue(Type valueType) { if (_statement != null) { if (valueType instanceof Class<?>) return getValue((Class<T>) valueType); else if (valueType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) valueType; if (parameterizedType.getRawType().equals(List.class) && (parameterizedType.getActualTypeArguments().length == 1)) { Type actualTypeArgument = parameterizedType.getActualTypeArguments()[0]; List<Object> list = new LinkedList<Object>(); NodeIterator bagIterator = _statement.getBag().iterator(); while (bagIterator.hasNext()) list.add(getValue(bagIterator.next(), (Class<?>) actualTypeArgument)); return (T) list; } return null; } else return null; } else return null; }
private boolean isItemInMarkupItem(Resource item, Set<Resource> visitedItems) { if (!visitedItems.contains(item)) { visitedItems.add(item); Set<Resource> subjects = model.listResourcesWithProperty(pitem_r, item).toSet(); subjects.addAll(model.listResourcesWithProperty(pfirstitem_r, item).toSet()); subjects.addAll(model.listResourcesWithProperty(plastitem_r, item).toSet()); Iterator<Resource> subjectsIte = subjects.iterator(); while (subjectsIte.hasNext()) { Resource resource = subjectsIte.next(); if ( visited.contains(resource) && document.getEntityById(resource.getURI()) instanceof MarkupItem) { return true; } } Set<Resource> objects = model.listResourcesWithProperty(pnextitem_r, item).toSet(); NodeIterator nodes = model.listObjectsOfProperty(item, ppreviousitem_r); while (nodes.hasNext()) { RDFNode node = nodes.next(); if (node.isResource()) { objects.add((Resource) node); } } Iterator<Resource> objectsIte = objects.iterator(); while (objectsIte.hasNext()) { if (isItemInMarkupItem(objectsIte.next(), visitedItems)) { return true; } } } return false; }