⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matchmakerinterface.java

📁 实现对owl-s描述服务的检索
💻 JAVA
字号:
/*
 * Created on 13.10.2005
 * 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.gui.util;

import java.net.URI;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
import owlsmx.data.MatchedService;
import owlsmx.exceptions.MatchingException;
import owlsmx.gui.data.HybridServiceItem;
import owlsmx.gui.data.ServiceItem;
import owlsmx.gui.data.TestCollection;
import owlsmx.similaritymeasures.SimilarityMeasure;

/**
 * @author Ben
 *
 */
public class MatchmakerInterface {	
	private String getSimType(int type) {
		switch(type){		
		case SimilarityMeasure.SIMILARITY_COSINE:
			return "OWLS M3: Cosine";
		case SimilarityMeasure.SIMILARITY_EXTENDED_JACCARD:
			return "OWLS M3: exJ";
		case SimilarityMeasure.SIMILARITY_JENSEN_SHANNON:
			return "OWLS M3: Jensen Shannon";
		case SimilarityMeasure.SIMILARITY_LOI:
			return "OWLS M3: LOI";
		default:
			return "OWLS M0: Semantic";				
	}	
		
	}
	
	private owlsmx.SimilarityMatchingEngine matcher=null;
	private static MatchmakerInterface _instance = new MatchmakerInterface();
	private boolean ranMatchmaker = false;
	
	public static MatchmakerInterface getInstance() {
		return _instance;
	}
	
	public void createMatchmaker() {
		short type = (short)GUIState.getInstance().getSimilarityMeasure();
		owlsmx.io.ErrorLog.debug("Similarity measure: " + getSimType(type));
		switch(type){		
			case SimilarityMeasure.SIMILARITY_COSINE:
				matcher = new owlsmx.SimilarityMatchingEngine(new owlsmx.similaritymeasures.CosineSimilarity());
				break;
			case SimilarityMeasure.SIMILARITY_EXTENDED_JACCARD:
				matcher = new owlsmx.SimilarityMatchingEngine(new owlsmx.similaritymeasures.ExtendedJaccardMeasure());
				break;
			case SimilarityMeasure.SIMILARITY_JENSEN_SHANNON:
				matcher = new owlsmx.SimilarityMatchingEngine(new owlsmx.similaritymeasures.JensenShannonMeasure());
				break;
			case SimilarityMeasure.SIMILARITY_LOI:
				matcher = new owlsmx.SimilarityMatchingEngine(new owlsmx.similaritymeasures.ConstraintSimilarity());
				break;
			default:
				matcher = new owlsmx.SimilarityMatchingEngine(null);				
		}		
		matcher.clear();
	}
	
	public SortedSet matchRequest(URI profileURI, int minimumDegreeOfMatch, double treshold) {
		try {				
			owlsmx.io.ErrorLog.debug("Matching request: " + profileURI);
			owlsmx.io.ErrorLog.debug("Minimum DOM: " + minimumDegreeOfMatch);
			owlsmx.io.ErrorLog.debug("Similarity treshold: " + treshold);		
			ranMatchmaker = true;
			//matcher.setSimilarityMeasure(GUIState.getInstance().getSimilarityMeasure());
			SortedSet tmpResult = matcher.matchRequest(profileURI, GUIState.getInstance().getMinDegree(), GUIState.getInstance().getTreshold());
			owlsmx.io.ErrorLog.debug("Resultat:\n   " + tmpResult);
			SortedSet result = MatchmakerToGUISet(tmpResult);			
			return result;
		} catch (MatchingException e) {
			e.printStackTrace();
			matcher = null;
			return new TreeSet();
		}
	}
	
	public void addService(URI profileURI) {
		try {
		if (matcher==null) {
			owlsmx.io.ErrorLog.debug(this.getClass().toString()+": Reset machmaker");
			createMatchmaker();
		}

		owlsmx.io.ErrorLog.debug(this.getClass().toString()+": Adding service: " + profileURI.toString());
		matcher.addService(profileURI);
		}
		catch(Exception e) {
			GUIState.displayWarning("Matchmaker", "Couldn't add service " + profileURI + " either file not found or not an valid OWL-S 1.1 file."); 
		}
		
	}
	
	private SortedSet MatchmakerToGUISet(SortedSet result) {		
		SortedSet hybrid = new TreeSet();
		if (result == null) {
			GUIState.displayWarning("Matchmaker", "Result set is empty");
//			ErrorLog.report("Matchmaker didn't return any result");
//			owlsmx.io.ErrorLog.debug("Matchmaker didn't return any result");
			return hybrid;
		}
//		owlsmx.io.ErrorLog.debug("Matchmaker result: " +  result);
		MatchedService m_result;
		HybridServiceItem h_result;
		ServiceItem s_item;
		for(Iterator iter = result.iterator();iter.hasNext();){
			m_result = (MatchedService) iter.next();
			s_item = TestCollection.getInstance().getService(m_result.serviceURI);
			h_result = new HybridServiceItem(s_item);
			h_result.setDegreeOfMatch(m_result.degreeOfMatch);
			h_result.setSyntacticSimilarity(m_result.similarity);
//			owlsmx.io.ErrorLog.debug(this.getClass().toString() + "|M2GUI: MResult " + m_result.toString());
			hybrid.add(h_result);
		}
		
		return hybrid;
	}
	
	public void clear() {
		matcher.clear();
		matcher = null;
		owlsmx.io.ErrorLog.debug(this.getClass().toString()+": Reset machmaker");
	}
	
	public boolean didRun() {
		return ranMatchmaker;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -