Package owlsmx.examples

Source Code of owlsmx.examples.CommandLineMatching

/*
* OWL-S Matchmaker
*
* COPYRIGHT NOTICE
*
* Copyright (C) 2005 DFKI GmbH, Germany
* Developed by Benedikt Fries, Matthias Klusch
*
* The code is free for non-commercial use only.
* You can redistribute it and/or modify it under the terms
* of the Mozilla Public License version 1.1  as
* published by the Mozilla Foundation at
* http://www.mozilla.org/MPL/MPL-1.1.txt
*/

package owlsmx.examples;

import java.io.File;
import java.net.URI;
import java.util.Iterator;
import java.util.SortedSet;

import owlsmx.SimilarityMatchingEngine;
import owlsmx.data.MatchedService;
import owlsmx.similaritymeasures.ConstraintSimilarity;
import owlsmx.similaritymeasures.CosineSimilarity;
import owlsmx.similaritymeasures.ExtendedJaccardMeasure;
import owlsmx.similaritymeasures.JensenShannonMeasure;
import owlsmx.similaritymeasures.SimilarityMeasure;

/**
* A simple command line utility that can perform simple service matchmaking
*
* @author bEn
*
*/
public class CommandLineMatching {
    private static SimilarityMatchingEngine engine;
    private static URI request;
    private static Integer matchingType;
    private static Integer minDegree = new Integer(5);
    private static Double minSim = new Double(0);
    private static File services;
   
    private static void fail(String message) {
        System.out.println(message);
        System.out.println("Example usage:");
        System.out.println("java -jar matching.jar [RequestURI|URI] [ServicesPath|String] [MatchingType|Int] [minDegree|Int] [minSim|Double] ");       
        }
   
    private static void addServices(File serviceDirectory) {
        if (!serviceDirectory.isDirectory())
            return;
        File[] files = serviceDirectory.listFiles();
        int max = files.length;
        for (int i=0;i<files.length;i++) {
            if (files[i].isFile()){               
                System.out.println("[ADD] " + (i+1) + "/" + max + " " + (files[i].toString()));
                engine.addService(files[i].toURI());
            }
            else
                System.out.println("[ADD] " + (i+1) + "/" + max + " Is a directory, not a file");
        }
    }
   
    private static SimilarityMeasure getSimilarityMeasure(int i) {
        switch(i){
        case 1:
            return new ConstraintSimilarity();
        case 2:
            return new ExtendedJaccardMeasure();
        case 3:
            return new CosineSimilarity();
        case 4:
            return new JensenShannonMeasure();
        default:
            return null;
        }
    }
     
    private static void printResult(SortedSet result) {
        Iterator iter = result.iterator();
        MatchedService service;
        while(iter.hasNext()) {
            service = (MatchedService) iter.next();
            System.out.println(service.toString());
        }
    }
   
    public static void main(String[] args) {
    //"java -jar matching.jar [RequestURI] [MatchingType] [minDegree] [minSim] [ClearOnExit] [ServicesPath]"
        if (args.length<3) {
            fail("Too few arguments")
            return;
        }       
        try {
           
            request = new URI(args[0]);
            matchingType = new Integer(args[2]);
            engine = new SimilarityMatchingEngine(getSimilarityMeasure(matchingType.intValue()));
            engine.load();
            if (args[1].toLowerCase().startsWith("file"))
                services = new File(new URI(args[1]) );
            else
                services = new File(args[1]);
            if (!services.isDirectory()){
                fail("Path to services must be a directory but was " + args[1]);
                return;
            }
            if (args.length>3)
                minDegree = new Integer(args[3]);          
            if (args.length>4)   
                minSim = new Double(args[4]);
            /*
            if (args.length>5)
                clear = Boolean.getBoolean(args[5]);
                */
           
        }
        catch(Exception e) {
            fail(e.toString());
            return;
        }
       
       
              
       
        if (services.isDirectory()) {
            addServices(services);
        }
        try {
        SortedSet result = engine.matchRequest(request,minDegree.intValue(),minSim.doubleValue());
        printResult(result);
        }
        catch(Exception e){
          fail(e.toString()); }
       
       
        //if (clear)
            engine.clear();
        //else
            //engine.save();

    }
}
TOP

Related Classes of owlsmx.examples.CommandLineMatching

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.