Ejemplo n.º 1
0
  /**
   * @param viskoService
   * @param inputDataURL
   * @param serviceIndex
   * @return
   * @throws ExecutionException
   */
  private String executeService(
      edu.utep.trustlab.visko.ontology.viskoService.Service viskoService,
      String inputDataURL,
      int serviceIndex)
      throws ExecutionException {

    OWLKnowledgeBase kb = OWLFactory.createKB();
    Service service = viskoService.getOWLSService().getIndividual();
    Process process = service.getProcess();

    ValueMap<Input, OWLValue> inputs =
        OWLSParameterBinder.buildInputValueMap(
            process, inputDataURL, job.getPipeline().getParameterBindings(), kb);

    String outputDataURL = null;

    if (inputs != null) {
      ValueMap<Output, OWLValue> outputs;

      if (job.isSimulated()) outputDataURL = ServiceSimulator.exec();
      else {
        outputs = exec.execute(process, inputs, kb);
        OWLDataValue out = (OWLDataValue) outputs.getValue(process.getOutput());
        outputDataURL = out.toString();
      }

      if (job.getProvenanceLogging()) {
        pmlLogger.recordServiceInvocation(viskoService, inputDataURL, outputDataURL, inputs);
        provLogger.recordServiceInvocation(viskoService, inputDataURL, outputDataURL, inputs);
      }
    }
    return outputDataURL;
  }
Ejemplo n.º 2
0
  public void runZipCode() throws Exception {
    OWLKnowledgeBase kb = OWLFactory.createKB();

    service = kb.readService("http://localhost:8080/Temperatura/owls/getNameCar_NameCar.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    values.setDataValue(process.getInput("arg0"), "CARRO");

    values = exec.execute(process, values);

    // get the result
    OWLIndividual out = values.getIndividualValue(process.getOutput());

    // display the results
    System.out.println("Executed service '" + service + "'");
    System.out.println(
        "Grounding WSDL: " + ((AtomicProcess) process).getGrounding().getDescriptionURL());
    System.out.println("City   = " + "College Park");
    System.out.println("State  = " + "MD");
    System.out.println("Output = ");
    System.out.println(Utils.formatRDF(out.toRDF()));
    System.out.println();
  }
Ejemplo n.º 3
0
  public void runTranslator() throws Exception {
    // language ontology
    String langOnt = "http://www.daml.org/2003/09/factbook/languages#";

    OWLKnowledgeBase kb = OWLFactory.createKB();
    // we at least need RDFS reasoning to evaluate preconditions (to understand
    // that process:Parameter is subclass of swrl:Variable)
    kb.setReasoner("RDFS");

    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/BabelFishTranslator.owl");
    process = service.getProcess();

    // get the references for these values
    OWLIndividual English = kb.getIndividual(URI.create(langOnt + "English"));
    OWLIndividual French = kb.getIndividual(URI.create(langOnt + "French"));

    // initialize the input values to be empty
    values = new ValueMap();

    values.setDataValue(process.getInput("InputString"), "Hello world!");
    values.setValue(process.getInput("InputLanguage"), English);
    values.setValue(process.getInput("OutputLanguage"), French);
    values = exec.execute(process, values);

    // get the output using local name
    outValue = values.getValue(process.getOutput()).toString();

    // display the results
    System.out.println("Executed service '" + service + "'");
    System.out.println(
        "Grounding WSDL: " + ((AtomicProcess) process).getGrounding().getDescriptionURL());
    System.out.println("Output = " + outValue);
    System.out.println();
  }
Ejemplo n.º 4
0
  public void runFindCheaperBook() throws Exception {
    OWLKnowledgeBase kb = OWLFactory.createKB();
    // we need a reasoner for example to work
    kb.setReasoner("Pellet");
    // we need to check preconditions so that local variables will be assigned values
    exec.setPreconditionCheck(true);

    // read the service description
    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/FindCheaperBook.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    // use an arbitrary book name
    values.setDataValue(process.getInput("BookName"), "City of Glass");
    values = exec.execute(process, values);

    // get the output values
    OWLIndividual price = values.getIndividualValue(process.getOutput("BookPrice"));
    String bookstore = values.getStringValue(process.getOutput("Bookstore"));

    // display the results
    System.out.println("Executed service " + service);
    System.out.println("Bookstore = " + bookstore);
    System.out.println("Price = ");
    System.out.println(Utils.formatRDF(price.toRDF()));
    System.out.println();
  }
Ejemplo n.º 5
0
  public void runBookPrice() throws Exception {
    String currencyOnt = "http://www.daml.ecs.soton.ac.uk/ont/currency.owl#";

    OWLKnowledgeBase kb = OWLFactory.createKB();

    // read the service description
    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/BookPrice.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    // use an arbitrary book name
    inValue = "City of Glass";
    // get the parameter using the local name
    values.setDataValue(process.getInput("BookName"), inValue);
    values.setValue(
        process.getInput("Currency"), kb.getIndividual(URI.create(currencyOnt + "EUR")));
    values = exec.execute(process, values);

    // get the output param using the index
    OWLIndividual out = values.getIndividualValue(process.getOutput());

    // display the results
    System.out.println("Executed service " + service);
    System.out.println("Book Name = " + inValue);
    System.out.println("Price = ");
    System.out.println(Utils.formatRDF(out.toRDF()));
    System.out.println();
  }
Ejemplo n.º 6
0
  public void runBookFinder() throws Exception {
    OWLKnowledgeBase kb = OWLFactory.createKB();

    // read the service description
    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    // use any book name
    inValue = "City of Glass";

    // get the parameter using the local name
    values.setDataValue(process.getInput("BookName"), inValue);
    values = exec.execute(process, values);

    // get the output param using the index
    OWLIndividual out = values.getIndividualValue(process.getOutput());

    // display the results
    System.out.println("Executing OWL-S service " + service);
    System.out.println(
        "Grounding WSDL: "
            + service
                .getGrounding()
                .getAtomicGrounding((AtomicProcess) process)
                .getDescriptionURL());
    System.out.println("BookName = " + inValue);
    System.out.println("BookInfo = ");
    System.out.println(Utils.formatRDF(out.toRDF()));
    System.out.println();
  }
Ejemplo n.º 7
0
  /**
   * Create a Sequence process for the processes of given services. Creates the data flow assuming
   * each service has one output and one input (except first and last one).
   */
  CompositeProcess createSequenceProcess(
      final CompositeProcess compositeProcess, final List<Service> services) {
    final Sequence sequence = ont.createSequence(null);
    compositeProcess.setComposedOf(sequence);

    final Perform[] performs = new Perform[services.size()];
    for (int i = 0; i < services.size(); i++) {
      final Service s = services.get(i);
      final Process p = s.getProcess();

      performs[i] = ont.createPerform(null);
      performs[i].setProcess(p);

      sequence.addComponent(performs[i]);

      if (i > 0) {
        final Perform prevPerform = performs[i - 1];
        final Input input = p.getInputs().get(0);
        final Output output = prevPerform.getProcess().getOutputs().get(0);

        // the value of 'input' is the value of 'output' from 'prevPerform'
        performs[i].addBinding(input, prevPerform, output);
      }
    }

    final Perform firstPerform = performs[0];
    final Perform lastPerform = performs[services.size() - 1];
    final boolean createInput = firstPerform.getProcess().getInputs().size() > 0;
    final boolean createOutput = lastPerform.getProcess().getOutputs().size() > 0;

    if (createInput) {
      final Input input = firstPerform.getProcess().getInputs().get(0);
      final Input newInput = ont.createInput(URIUtils.createURI(baseURI, "TestInput"));
      newInput.setLabel(input.getLabel(null), null);
      newInput.setParamType(input.getParamType());
      newInput.setProcess(compositeProcess);

      // input of the first perform is directly read from the input of the composite process
      performs[0].addBinding(input, OWLS.Process.ThisPerform, newInput);
    }

    if (createOutput) {
      final Output output = lastPerform.getProcess().getOutputs().get(0);
      final Output newOutput = ont.createOutput(URIUtils.createURI(baseURI, "TestOutput"));
      newOutput.setLabel(output.toPrettyString(), null);
      newOutput.setParamType(output.getParamType());
      newOutput.setProcess(compositeProcess);

      // the output of the composite process is the output pf last process
      final Result result = ont.createResult(null);
      result.addBinding(newOutput, lastPerform, output);

      compositeProcess.addResult(result);
    }

    return compositeProcess;
  }
Ejemplo n.º 8
0
  /**
   * Create a Profile for the composite service. We only set the input and output of the profile
   * based on the process.
   */
  Profile createProfile(final Profile profile, final Process process) {
    for (Input input : process.getInputs()) {
      profile.addInput(input);
    }

    for (Output output : process.getOutputs()) {
      profile.addOutput(output);
    }

    return profile;
  }
Ejemplo n.º 9
0
  public void runTest() throws Exception {
    // create an OWL-S knowledge base
    final OWLKnowledgeBase kb = OWLFactory.createKB();

    // create an empty ontology in this KB
    ont = kb.createOntology(URIUtils.standardURI(baseURI));

    // create an execution engine
    final ProcessExecutionEngine exec = OWLSFactory.createExecutionEngine();

    // load two services
    final Service s1 = kb.readService(ExampleURIs.BOOK_FINDER_OWLS12);
    final Service s2 = kb.readService(ExampleURIs.BN_BOOK_PRICE_OWLS12);

    // put the services in a list
    final List<Service> services = new ArrayList<Service>();
    services.add(s1);
    services.add(s2);

    // create a new service as a sequence of the list
    final Service s = createSequenceService(services);

    // print the description of new service to standard output
    ont.write(System.out, baseURI);
    System.out.println();

    // get the process of the new service
    final Process process = s.getProcess();
    // initialize the input values to be empty
    ValueMap<Input, OWLValue> inputs = new ValueMap<Input, OWLValue>();
    // get the parameter using the local name
    inputs.setValue(process.getInputs().get(0), kb.createDataValue("City of Glass"));

    // execute the service
    System.out.print("Executing...");
    ValueMap<Output, OWLValue> outputs = exec.execute(process, inputs, kb);
    System.out.println("done");

    // get the output parameter using the index
    final OWLIndividual outValue = outputs.getIndividualValue(process.getOutput());

    // display the result
    System.out.println("Book Price = ");
    System.out.println(Utils.formatRDF(outValue.toRDF(true, true)));
    System.out.println();
  }
Ejemplo n.º 10
0
  public void runCurrencyConverter() throws Exception {
    String currencyOnt = "http://www.daml.ecs.soton.ac.uk/ont/currency.owl#";
    String conceptsOnt = "http://www.mindswap.org/2004/owl-s/concepts.owl#";

    OWLKnowledgeBase kb = OWLFactory.createKB();
    // read the service description
    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/CurrencyConverter.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    OWLIndividual EUR = kb.getIndividual(URI.create(currencyOnt + "EUR"));
    values.setValue(process.getInput("OutputCurrency"), EUR);

    OWLIndividual USD = kb.getIndividual(URI.create(currencyOnt + "USD"));

    OWLClass Price = kb.getClass(URI.create(conceptsOnt + "Price"));
    OWLObjectProperty currency = kb.getObjectProperty(URI.create(conceptsOnt + "currency"));
    OWLDataProperty amount = kb.getDataProperty(URI.create(conceptsOnt + "amount"));

    OWLIndividual inputPrice = kb.createInstance(Price);
    inputPrice.addProperty(currency, USD);
    inputPrice.addProperty(amount, "100");

    // get the parameter using the local name
    values.setValue(process.getInput("InputPrice"), inputPrice);

    values = exec.execute(process, values);

    // get the output param using the index
    OWLIndividual out = values.getIndividualValue(process.getOutput());

    // display the results
    System.out.println("Executed service " + service);
    System.out.println(
        "Grounding WSDL: " + ((AtomicProcess) process).getGrounding().getDescriptionURL());
    System.out.println("Input  = ");
    System.out.println(Utils.formatRDF(inputPrice.toRDF()));
    System.out.println("Output = ");
    System.out.println(Utils.formatRDF(out.toRDF()));
    System.out.println();
  }
Ejemplo n.º 11
0
  public void runDictionary() throws Exception {
    OWLKnowledgeBase kb = OWLFactory.createKB();
    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    inValue = "hello";
    values.setDataValue(process.getInput("InputString"), inValue);
    values = exec.execute(process, values);

    // get the output
    OWLDataValue out = (OWLDataValue) values.getValue(process.getOutput());

    // display the results
    System.out.println("Executed service '" + service + "'");
    System.out.println(
        "Grounding WSDL: " + ((AtomicProcess) process).getGrounding().getDescriptionURL());
    System.out.println("Input  = " + inValue);
    System.out.println("Output = " + out.toString());
    System.out.println();
  }
Ejemplo n.º 12
0
  public void runFrenchDictionary() throws Exception {
    OWLKnowledgeBase kb = OWLFactory.createKB();
    // we need a reasoner that can evaluate the precondition of the translator
    kb.setReasoner("Pellet");

    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/FrenchDictionary.owl");
    process = service.getProcess();

    // initialize the input values to be empty
    values = new ValueMap();

    inValue = "mere";
    values.setDataValue(process.getInput("InputString"), inValue);
    values = exec.execute(process, values);

    // get the output using local name
    outValue = values.getValue(process.getOutputs().getParameter("OutputString")).toString();

    // display the results
    System.out.println("Executed service " + service);
    System.out.println("Input  = " + inValue);
    System.out.println("Output = " + outValue);
    System.out.println();
  }
Ejemplo n.º 13
0
 /** @return The name of the process, its URI, or its anon identifier. */
 public String getProcessName() {
   String pn = getProcess().getName();
   pn = (pn != null) ? pn : (process.isAnon()) ? process.getAnonID() : process.getURI().toString();
   return pn;
 }
Ejemplo n.º 14
0
 /* @see org.mindswap.owls.process.variable.ProcessVar#setProcess(org.mindswap.owls.process.Process) */
 public void setProcess(final Process process) {
   process.addInput(this);
 }
Ejemplo n.º 15
0
 /* (non-Javadoc)
  * @see org.mindswap.owls.process.Parameter#getService()
  */
 public Service getService() {
   Process process = getProcess();
   return (process == null) ? null : process.getService();
 }
Ejemplo n.º 16
0
 /* (non-Javadoc)
  * @see org.mindswap.owls.process.Parameter#getProcess(org.mindswap.owls.process.Process)
  */
 public void setProcess(Process process) {
   process.addParameter(this);
 }