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

📄 cogitantclient.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
字号:
package toocom.ocgl;

import java.net.*;
import java.io.*;
import java.util.*;
import toocom.exceptions.*;

/**
 * This class represents the client which communicates with the Cogitant server. It provides
 * methods to create conceptual objects on the server and to manipulate these objects.
 *
 * @author Fr閐閞ic F黵st
 */
public class CogitantClient{
	
	private Socket socket;
	private PrintStream os;
	private BufferedReader is;
	// 0=no trace, 1=minimum trace, 2=complete trace
	private int trace;
	// Current environment id : -1 if any environment exists
	private int currentEnvironment;
	// Correspondance table idOCG/idCogitant (String/idCogitant for the non ontological instances)
	private Hashtable idCorrespondances;
	
	/** The client is created on the given IP adress and the given port number. The trace variable 
	 *  is used to show or hide messages on the console. */
	public CogitantClient(String ip,int port,int trace) throws IOException{
		this.socket = new Socket(ip,port);
		this.os = new PrintStream(socket.getOutputStream());
		this.is = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
		this.trace = trace;
		this.idCorrespondances = new Hashtable();
		this.currentEnvironment = -1;
	}
	
	/** Returns the server id corresponding to the given client id, -1 if any such client id 
	 *  exists. */
	public int getServerId(int clientId){
		Integer i = (Integer) this.idCorrespondances.get(new Integer(clientId));
		if(i != null) return i.intValue();
		else return -1;
	}
	
	/** Returns the client concept type id corresponding to the given server id, -1 if 
	 *  any such server id exists. */
	public int getClientConceptTypeId(Ontology onto, int serverId){
		for(Iterator i = onto.getConceptTypes().iterator();i.hasNext();){
			ConceptType ct = (ConceptType) i.next();
			if(this.getServerId(ct.getId()) == serverId) return ct.getId();	
		}
		return -1;
	}
	
	/** Returns the client relation type id corresponding to the given server id, -1 if 
	 *  any such server id exists. */
	public int getClientRelationTypeId(Ontology onto, int serverId){
		for(Iterator i = onto.getRelationTypes().iterator();i.hasNext();){
			RelationType rt = (RelationType) i.next();
			if(this.getServerId(rt.getId()) == serverId) return rt.getId();	
		}
		return -1;
	}
	
	/** Returns the client individual id corresponding to the given server id, -1 if 
	 *  any such server id exists. */
	public int getClientIndividualId(Ontology onto, int serverId){
		for(Iterator i = onto.getIndividuals().iterator();i.hasNext();){
			Individual ind = (Individual) i.next();
			if(this.getServerId(ind.getId()) == serverId) return ind.getId();	
		}
		return -1;
	}
	
	/** Read an answer on the input stream. */
	public Vector getAnswer() throws IOException{
		Vector v = new Vector();
		String tmp;
		do{
			tmp = this.is.readLine();
			v.add(tmp);
		}while (! tmp.equals("</cogitantanswer>"));
		// La fin d'un message cogitantanswer est marqu閑 par un caract鑢e EOF
		// Qui est "pass

⌨️ 快捷键说明

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