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

📄 rdfschemasourcepool.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			return distributed; 		}		// Compute interval on which instanceOf relations are retrieved.		double interval = (double)totalInstanceOf/preferredSize;		// Iterate over all classes and construct and add Binary object		// representing instanceOf relation to distributed if on interval. 		Iterator j = _classesX.iterator();		// If interval is smaller than or equal to one then preferredSize is		// equal to or exceeds totalInstanceOf and distributed is equal to all		// instanceOf relations. Else relations are distributed evenly. 		if (interval <= 1) {	 		while (j.hasNext()) {				Resource classResource = (Resource)j.next();				StatementIterator k;				if (mostSpecific) {					k = _rdfSchemaSource.getDirectType(null, classResource);				}				else {					k = _rdfSchemaSource.getType(null, classResource);				}				while(k.hasNext()) {					Resource instance = k.next().getSubject();					if (instance instanceof URI) {						distributed.add(new Binary(									_stripId(instance),									_stripId(classResource)));					}				}				k.close();			}		}		else {			/* This algorithm only connects to repository if current class			 * iterator returns has instanceOf relations on interval and skips			 * rest.			 *			 * Position of next instanceOf relation.			 */			int position = 0;			double lookAhead = 0;			while (j.hasNext()) {				Resource classResource = (Resource)j.next();				// Get number of instances.				int numberOfInstances =					((Integer)numbersOfInstanceOf.get(classResource)).intValue();				// Look ahead.				lookAhead = lookAhead + numberOfInstances;				if (lookAhead >= interval ||					position == totalInstanceOf - numberOfInstances) {					// classResource has instanceOf relations on interval,					// connect to repository.					StatementIterator k;					if (mostSpecific) {						k = _rdfSchemaSource.getDirectType(null, classResource);					}					else {						k = _rdfSchemaSource.getType(null, classResource);					}										while (k.hasNext()) {						Resource instance = k.next().getSubject();						if (instance instanceof URI) {							position++;							/* Computation of last position modulo interval should							 * be zero and therefore last instanceOf relation							 * iterator returns should be added to distributed.							 * Because of possible loss of precision, computation							 * could fail and last instanceOf relation is will							 * not be added to distributed. To avoid this,							 * another check is made, i.e. is current position							 * equal to last position.							 */							if (position % interval < 1 ||								position == totalInstanceOf) {								// Position on interval.								distributed.add									(new Binary(_stripId(instance),												_stripId(classResource)));							}						}					}					k.close();					lookAhead = lookAhead % interval;				}				else {					// Skip classResource.					position += numberOfInstances;				}			}		}		return distributed;	}	/* Creates a List of subClassOf relations represented by object	 * Binary with size is preferredSize. SubClassOf relations are	 * distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getSubClassOfRelations(int preferredSize, boolean direct) {		// Collect all subClassOf relations.		List all = null;		if (direct) {			all = _directSubClassOf;		}		else {			all = _subClassOf;		}		int size = all.size();		if (size == 0) {			String warning = "Warning. Repository has no ";			if (direct) {				warning += "direct ";			}			warning += "subClassOf relations.";			_warning(warning);			return new ArrayList();		}		else {			// Else distribute subClassOf relations in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of subPropertyOf relations represented by object	 * Binary with size is preferredSize. SubPropertyOf relations are	 * distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getSubPropertyOfRelations(			int preferredSize, boolean direct)	{		// Collect all subPropertyOf relations.		List all = null;		if (direct) {			all = _directSubPropertyOf;		}		else {			all = _subPropertyOf;		}		int size = all.size();		if (size == 0) {			String warning = "Repository has no ";			if (direct) {				warning += "direct ";			}			warning += "subPropertyOf relations.";			_warning(warning);			return all;		}		else {			// Else distribute subPropertyOf relations in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of indirect subClassOf relations represented by object	 * Binary with size is preferredSize. SubClassOf relations are distributed	 * evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getIndirectSubClassOfRelations(int preferredSize) {		// Collect all indirect subClassOf relations. All indirect subClassOf		// relations are equal to all relations minus direct relations.		Set indirectSubClassOf = new HashSet(_subClassOf);		indirectSubClassOf.removeAll(_directSubClassOf);		int size = indirectSubClassOf.size();		if (size  == 0) {			_warning("Repository has no indirect subClassOf relations.");			return new ArrayList();		}		else {			// Else distribute indirect subClassOf relations in			// indirectSubClassOf over new List.			return _distribute(indirectSubClassOf, preferredSize);		}	}	/* Creates a List of indirect subPropertyOf relations represented by object	 * Binary with size is preferredSize. SubPropertyOf relations are distributed	 * evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getIndirectSubPropertyOfRelations(int preferredSize) {		// Collect all indirect subPropertyOf relations. All indirect		// subPropertyOf relations are equal to all relations minus direct		// relations.		Set indirectSubPropertyOf = new HashSet(_subPropertyOf);		indirectSubPropertyOf.removeAll(_directSubPropertyOf);		int size = indirectSubPropertyOf.size();		if (size  == 0) {			_warning("Repository has no indirect subPropertyOf relations.");			return new ArrayList();		}		else {			// Else distribute indirect subPropertyOf relations in			// indirectSubPropertyOf over new List.			return _distribute(indirectSubPropertyOf, preferredSize);		}	}	/* Creates a List of indirect instanceOf relations represented by object	 * Binary with size is preferredSize. InstanceOf relations are distributed	 * evenly over repository.	 *	 * Optimized approach, a combination of streaming and in memory...	 */	protected List _getNotProperInstanceOfRelations(int preferredSize) {		// For each class, count number of not proper instances. Also count total		// number of not proper instanceOf relations. Number of not proper		// instances is equal to total number of instances minus proper number of		// instances.		Map numbersOfNotProperInstanceOf = new HashMap();		int totalNotProperInstanceOf = 0;	 	Iterator i = _classesX.iterator(); 		while (i.hasNext()) {			Resource classResource = (Resource)i.next();			// Get number of proper instances.			int properInstanceOf =				((Integer)_numbersOfProperInstances.get(classResource)).intValue();			// Get number of instances.			int instanceOf =				((Integer)_numbersOfInstances.get(classResource)).intValue();			int notProperInstanceOf = instanceOf - properInstanceOf;			totalNotProperInstanceOf += notProperInstanceOf;			// Save number of not proper instances of classResource.			numbersOfNotProperInstanceOf.put				(classResource, new Integer(notProperInstanceOf));		}		List distributed = new ArrayList();		if (totalNotProperInstanceOf == 0) {			_warning("Repository has no not proper instanceOf relations.");			return distributed; 		}		// Compute interval on which not proper instanceOf relations are		// retrieved.		double interval = (double)totalNotProperInstanceOf/preferredSize;		// Iterate over all classes and construct and add Binary object		// representing not proper instanceOf relation to distributed if on		// interval. 		Iterator j = _classesX.iterator();		// If interval is smaller than or equal to one then preferredSize is		// equal to or exceeds totalNotProperInstanceOf and distributed is equal		// to all not proper instanceOf relations. Else relations are distributed		// evenly. 		if (interval <= 1) {	 		while (j.hasNext()) {				Resource classResource = (Resource)j.next();				// Not proper instances are equal to all instances minus proper				// instances.				Set notProperInstances = _toSet(						_rdfSchemaSource.getType(null, classResource));				Set properInstances = _toSet(						_rdfSchemaSource.getDirectType(null, classResource));				notProperInstances.removeAll(properInstances);				Iterator k = notProperInstances.iterator();				while(k.hasNext()) {					distributed.add(new Binary						(_stripId((Value)k.next()), _stripId(classResource)));				}			}		}		else {			// This algorithm only connects to repository if current class			// iterator returns has not proper instanceOf relations on interval			// and skips rest.			// Position of next not proper instanceOf relation.			int position = 0;			double lookAhead = 0;			while (j.hasNext()) {				Resource classResource = (Resource)j.next();				// Get number of not proper instances.				int numberOfNotProperInstanceOf =					((Integer)numbersOfNotProperInstanceOf.get(classResource)).intValue();				// Look ahead.				lookAhead = lookAhead + numberOfNotProperInstanceOf;				if (lookAhead >= interval ||					position == totalNotProperInstanceOf - numberOfNotProperInstanceOf) {					// Class has instanceOf relations on interval, connect to					// repository.					Set notProperInstances = _toSet(							_rdfSchemaSource.getType(null, classResource));					Set properInstances = _toSet(							_rdfSchemaSource.getDirectType(null, classResource));					notProperInstances.removeAll(properInstances);					Iterator k = notProperInstances.iterator();					while(k.hasNext()) {						position++;						// Computation of last position module interval should be						// zero and therefore last not proper instanceOf relation						// should be added to distributed. Because of possible						// loss of precision, computation could fail and last not						// proper instanceOf relation will not be added to						// distributed. To avoid this, another check is made,						// i.e. is current position equal to last position.						if (position % interval < 1 ||							position == totalNotProperInstanceOf) {							// Position on interval.							distributed.add(new Binary(_stripId((Value)k.next()),													   _stripId(classResource)));						}						else {							k.next();						}					}					lookAhead = lookAhead % interval;				}				else {					// Skip classResource.					position += numberOfNotProperInstanceOf;				}			}		}		return distributed;	}	/* Creates a List of subClassOf relations represented by object	 * Binary with size is preferredSize. Each Binary represents	 * two classes which are NOT a subClass of eachother. SubClassOf relations	 * are distributed evenly over repository.	 *	 * Optimized approach, a combination of streaming and in memory...	 */	protected List _getNoSubClassOfRelations(int preferredSize) {		// For each class, count number of classes which are not a subClass of		// class. Also count total number of subClassOf relations which do not		// exist. Number of classes which are not a subClass of class is equal		// to total number of classes minus number of subClasses of class.		Map numbersOfNoSubClasses = new HashMap();		int totalNoSubClassOf = 0; 		int numberOfClasses = _classes.size();		Iterator i = _classes.iterator(); 		while (i.hasNext()) {			Resource superClass = (Resource)i.next();			// Get number of subClasses.			int subClasses =				((Integer)_numbersOfSubClasses.get(superClass)).intValue();			int noSubClasses = numberOfClasses - subClasses;			totalNoSubClassOf += noSubClasses;			// Save number of classes which are not a subClass of superClass.			numbersOfNoSubClasses.put(superClass, new Integer(noSubClasses));		}		List distributed = new ArrayList();		if (totalNoSubClassOf == 0) {			_warning("Repository has no subClassOf relations which do not exist.");			return distributed; 		}		// Compute interval on which subClassOf relations which do not exist are		// retrieved.		double interval = (double)totalNoSubClassOf/preferredSize;		// Iterate over all classes and construct and add Binary object		// representing a subClassOf relation which does exist to distributed if		// on interval.		Iterator j = _classes.iterator();		// If interval is smaller than or equal to one then preferredSize is		// equal to or exceeds totalNoSubClassOf and distributed is equal to all		// subClassOf relations which do not exist. Else relations are		// distributed evenly. 		if (interval <= 1) {	 		while (j.hasNext()) {		 		Resource classResource = (Resource)j.next();				// Classes which are not a subClass of class are equal to all

⌨️ 快捷键说明

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