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

📄 rdfschemasourcepool.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		i.close();		int size = all.size();		if (size == 0) {			_warning				("Repository has no resources which are not a proper member of some class.");			return all;		}		else {			// Else distribute resources in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of resources. Resources are distributed evenly over	 * repository.	 *	 * Default approach...	 */	protected List _getResources(int preferredSize) {		int size = ((Integer)_numbersOfInstances.get(URIImpl.RDFS_RESOURCE)).intValue();		if (size == 0) {			_warning("Repository has no resources.");			return new ArrayList();		}		// Compute interval on which resources are retrieved.		double interval = (double)size/preferredSize;		// Iterate over all resources and add resource to distributed if on		// interval.		List distributed = new ArrayList();		StatementIterator j = _rdfSchemaSource.getType(null, URIImpl.RDFS_RESOURCE);		/* If interval is smaller than or equal to one then preferredSize is		 * equal to or exceeds size and distributed is equal to all resources.		 * Else resources are distributed evenly.		 */		if (interval <= 1) {			while (j.hasNext()) {				Resource resource = j.next().getSubject();				if (resource instanceof URI) {					distributed.add(_stripId(resource));				}			}		}		else {			int position = 0;			while (j.hasNext()) {				Resource resource = j.next().getSubject();				if (resource instanceof URI) {					position++;					/* Computation of last position module interval should be					 * zero and therefore last resource iterator returns should					 * be added to distributed. Because of possible loss of					 * precision, computation could fail and last resource 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 == size) {						// Position on interval.						distributed.add(_stripId(resource));					}				}			}		}		j.close();		return distributed;	}	/* Creates a List of literals. Literals are distributed evenly over	 * repository.	 *	 * Default approach...	 */	protected List _getLiterals(int preferredSize) {		int size =			((Integer)_numbersOfInstances.get(new URIImpl(RDFS.LITERAL))).intValue();		if (size == 0) {			_warning("Repository has no literals.");			return new ArrayList();		}		// Compute interval on which resources are retrieved.		double interval = (double)size/preferredSize;		/* Iterate over all literals and add literal to distributed if and on		 * interval.		 */		List distributed = new ArrayList();		StatementIterator j = _rdfSchemaSource.getType(null, URIImpl.RDFS_LITERAL);		/* If interval is smaller than or equal to one then preferredSize is		 * equal to or exceeds size and distributed is equal to all literals.		 * Else literals are distributed evenly.		 */		if (interval <= 1) {			while (j.hasNext()) {				distributed.add(_stripId(j.next().getSubject()));			}		}		else {			int position = 0;			while (j.hasNext()) {				position++;				/* Computation of last position modulo interval should be zero				 * and therefore last value iterator returns should be added to				 * distributed. Because of possible loss of precision,				 * computation could fail and last element 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 == size) {					// Position on interval.					distributed.add(_stripId(j.next().getSubject()));				}				else {					j.next();				}			}		}		j.close();		return distributed;	}	/* Creates a List of properties which are a direct superProperty of some	 * subProperty. Properties are distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getDirectSuperProperties(int preferredSize) {		/* Collect all properties which are a direct superProperty of some		 * subProperty.		 */		List all = new ArrayList();		Iterator i = _properties.iterator();		while (i.hasNext()) {			Resource property = (Resource)i.next();			// Get number of direct subProperties.			if (((Integer)_numbersOfDirectSubProperties.get(property)).intValue() > 1) {				// property has a direct subProperty, add it to List.				all.add(property);			}		}		int size = all.size();		if (size == 0) {			_warning("Repository has no direct superProperties.");			return all;		}		else {			// Else distribute superProperties in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of classes which are a direct superClass of some	 * subClass. Classes are distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getDirectSuperClasses(int preferredSize) {		// Collect all classes which are a direct superClass of some subClass.		List all = new ArrayList();		Iterator i = _classes.iterator();		while (i.hasNext()) {			Resource classResource = (Resource)i.next();			// Get number of direct subClasses.			if (((Integer)_numbersOfDirectSubClasses.get(classResource)).intValue() > 1) {				// classResource has a direct subClass, add it to List.				all.add(classResource);			}		}		int size = all.size();		if (size == 0) {			_warning("Repository has no direct superClasses.");			return all;		}		else {			// Else distribute superClasses in all over new List.			return _distribute(all, preferredSize);		}	} 	/* Creates a List of classes which are a direct subClass of some	 * superClass. Classes are distributed evenly over repository.	 */ 	protected List _getDirectSubClasses(int preferredSize) {		// Collect all classes which are a direct subClass of some superClass.  		List all = new ArrayList();	 	Iterator i = _classes.iterator(); 		while (i.hasNext()) {	 		Resource classResource = (Resource)i.next();		 	StatementIterator j =					_rdfSchemaSource.getDirectSubClassOf(classResource, null); 			if (j.hasNext()) {				// classResource has a direct superClass, add it to List.	 			all.add(classResource);			}		 	j.close(); 		}		int size = all.size();		if (size == 0) {			_warning("Repository has no direct subClasses.");			return all;		}		else {			// Else distribute subClasses in all over new List.			return _distribute(all, preferredSize);		}	} 	/* Creates a List of properties which are a direct subProperty of some	 * superProperty. Properties are distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */ 	protected List _getDirectSubProperties(int preferredSize) {		/* Collect all properties which are a direct subProperty of some		 * superProperty.		 */ 		List all = new ArrayList();	 	Iterator i = _properties.iterator(); 		while (i.hasNext()) {	 		Resource property = (Resource)i.next();			// Get number of direct superProperties.			if (((Integer)_numbersOfDirectSuperProperties.get(property)).intValue() > 1) {				// property has a direct superProperty, add it to List.				all.add(property);			} 		}		int size = all.size();		if (size == 0) {			_warning("Repository has no direct subProperties.");			return all;		}		else {			// Else distribute subProperties in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of classes which have no subClasses. Classes are	 * distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getLeafClassNodes(int preferredSize) {		/* Collect all classes which have no subClasses, these are all classes		 * with one indirect subclass, i.e. itself.		 */		List all = new ArrayList();		Iterator i = _classes.iterator();		while (i.hasNext()) {			Resource classResource = (Resource)i.next();			// Get number of subClasses.			if (((Integer)_numbersOfSubClasses.get(classResource)).intValue() == 1) {				// classResource has more than one indirect subClass.				all.add(classResource);			}		}		int size = all.size();		if (size == 0) {			_warning("Repository has no leaf classes.");			return all;		}		else {			// Else distribute leaf classnodes in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of properties which have no subProperties. Properties are	 * distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getLeafPropertyNodes(int preferredSize) {		/* Collect all of properties which have no subProperties, these are all		 * properties with one indirect subproperty, i.e. itself.		 */		List all = new ArrayList();		Iterator i = _properties.iterator();		while (i.hasNext()) {			Resource property = (Resource)i.next();			// Get number of subProperties.			if (((Integer)_numbersOfSubProperties.get(property)).intValue() == 1) {				// property has more than one indirect subProperty.				all.add(property);			}		}		int size = all.size();		if (size == 0) {			_warning("Repository has no leaf properties.");			return all;		}		else {			// Else distribute leaf propertynodes in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of properties which have no superProperties. Properties are	 * distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getRootPropertyNodes(int preferredSize) {		/* Collect all properties which have no superProperties, these are all		 * properties with one indirect superproperty, i.e. itself.		 */		List all = new ArrayList();		Iterator i = _properties.iterator();		while (i.hasNext()) {			Resource property = (Resource)i.next();			// Get number of direct superProperties.			if (((Integer)_numbersOfDirectSuperProperties.get(property)).intValue() == 1) {				// property has more than one indirect superProperty.				all.add(property);			}		}		int size = all.size();		if (size == 0) {			_warning("Repository has no root properties.");			return all;		}		else {			// Else distribute root propertynodes in all over new List.			return _distribute(all, preferredSize);		}	}	/* Creates a List of instanceOf relations between a resource and a class	 * represented by object Binary with size is preferredSize. InstanceOf	 * relations are distributed evenly over repository.	 *	 * Optimized approach, combination of streaming and in memory...	 */	protected List _getInstanceOfRelations		(int preferredSize, boolean mostSpecific) {		/* For each class, count number of instances. Also count total number of		 * instanceOf relations.		 */		Map numbersOfInstanceOf = new HashMap();		int totalInstanceOf = 0;	 	Iterator i = _classesX.iterator(); 		while (i.hasNext()) {			Resource classResource = (Resource)i.next();			int instances = 0;			/* Get number of proper instances or instances depending on			 * mostSpecific.			 */			if (mostSpecific) {				instances =					((Integer)_numbersOfProperInstances.get(classResource)).intValue();			}			else {				instances =					((Integer)_numbersOfInstances.get(classResource)).intValue();			}			totalInstanceOf += instances;			// Save number of instances of classResource.			numbersOfInstanceOf.put(classResource, new Integer(instances));		}		List distributed = new ArrayList();		if (totalInstanceOf == 0) {			_warning				("Repository has no subClassOf relations which do not exist.");

⌨️ 快捷键说明

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