コード例 #1
0
ファイル: CreateSequence.java プロジェクト: OldBao/mozart
  /**
   * 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;
  }
コード例 #2
0
ファイル: CreateSequence.java プロジェクト: OldBao/mozart
  /**
   * 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;
  }
コード例 #3
0
ファイル: CreateSequence.java プロジェクト: OldBao/mozart
  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();
  }