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

📄 rdfschemasourcepool.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				}			}			j.close();			_numbersOfDirectSuperProperties.put(property, new Integer(superProperties)); 		} 		_status("Buffering done.");		super._initialize();		_status("Searching for resources...");		resources = _getResources(50); 		_status("Searching for resources which are not a proper member of a class..."); 	 	notProperMembers = _getNotProperMembers(100);		_status("Searching for resources which are not a class..."); 		noClasses = _getNoClasses(99);		_status("Searching for resources which are not a property...");		noProperties = _getNoProperties(99);		_status("Searching for literals...");		literals = _getLiterals(50);		_status("Searching for explicit statements..."); 	 	explicitStatements = _getStatements(16, true);		_status("Searching for explicit statements which do not exist...");		noExplicitStatements = _getNoExplicitStatements(8); 		_status("Searching for classes..."); 		classes = _getClasses(100);		_status("Searching for classes which can be instantiated by some resource...");	 	classes2 = _getClassesX(13); 		_status("Searching for classes which are instantiated by some resource(rdfs:Resource not included)..."); 		instantiatedClasses = _getInstantiatedClasses(99, false); 		_status("Searching for classes which are proper instantiated by some resource(rdfs:Resource not included)..."); 		properInstantiatedClasses = _getInstantiatedClasses(100, true);	 	_status("Searching for classes which are not instantiated...");		notInstantiatedClasses = _getNotInstantiatedClasses(49, false);	 	_status("Searching for classes which are not proper instantiated...");	 	notProperInstantiatedClasses = _getNotInstantiatedClasses(33, true);		// Every class is a superClass of itself.	 	_status("Searching for superClasses...");		if (_classes.size() == 0) {			_warning("Repository has no superClasses.");			superClasses = new ArrayList();		}		else {			superClasses = _stripIds(_cutDown(_classes, 100));		}	 	_status("Searching for direct superClasses...");		directSuperClasses = _getDirectSuperClasses(100);  		_status("Searching for leaf classes...");	 	leafClasses = _getLeafClassNodes(50);		// Every class is a subClass of itself. 	 	_status("Searching for subClasses...");		if (_classes.size() == 0) {			_warning("Repository has no subClasses.");			subClasses = new ArrayList();		}		else {			subClasses = _stripIds(_cutDown(_classes, 100));		} 	 	_status("Searching for direct subClasses..."); 		directSubClasses = _getDirectSubClasses(100);		_status("Searching for root classes...");		/* A rootnode is a class with one implicit superClass, i.e. itself. This		 * should be rdfs:Resource.		 */  		rootClasses = new ArrayList(); 		rootClasses.add(new URIImpl(RDFS.RESOURCE));		_status("Searching for properties...");		properties = _getProperties(100);		// Every property is a superProperty of itself. 		_status("Searching for superProperties...");		if (properties.size() == 0) {			_warning("Repository has no superProperties.");			superProperties = new ArrayList();		}		else {			superProperties = _stripIds(_cutDown(properties, 100));		} 		_status("Searching for direct superProperties...");		directSuperProperties = _getDirectSuperProperties(100);		_status("Searching for leaf properties..."); 		leafProperties = _getLeafPropertyNodes(50);		// Every property is a superProperty of itself.		_status("Searching for subProperties..."); 		if (_properties.size() == 0) {			_warning("Repository has no subProperties.");			subProperties = new ArrayList();		}		else {	 		subProperties = _stripIds(_cutDown(_properties, 100));		}		_status("Searching for direct subProperties...");		directSubProperties = _getDirectSubProperties(100);  		_status("Searching for root properties...");	 	rootProperties = _getRootPropertyNodes(50);		_status("Searching for subClassOf relations...");  	  	subClassOfRelations = _getSubClassOfRelations(100, false);		_status("Searching for direct subClassOf relations..."); 		directSubClassOfRelations = _getSubClassOfRelations(100, true);		_status("Searching for indirect subClassOf relations..."); 		indirectSubClassOfRelations = _getIndirectSubClassOfRelations(11);		_status("Searching for subClassOf relations which do not exist...");		noSubClassOfRelations = _getNoSubClassOfRelations(13);		_status("Searching for subPropertyOf relations..."); 	 	subPropertyOfRelations = _getSubPropertyOfRelations(50, false);		_status("Searching for direct subPropertyOf relations...");		directSubPropertyOfRelations = _getSubPropertyOfRelations(50, true);		_status("Searching for indirect subPropertyOf relations...");		indirectSubPropertyOfRelations = _getIndirectSubPropertyOfRelations(11);		_status("Searching for subPropertyOf relations which do not exist...");   		noSubPropertyOfRelations = _getNoSubPropertyOfRelations(11);	 	_status("Searching for instanceOf relations...");  		instanceOfRelations = _getInstanceOfRelations(100, false);	 	_status("Searching for proper instanceOf relations...");	  	properInstanceOfRelations = _getInstanceOfRelations(50, true);	 	_status("Searching for not proper instanceOf relations..."); 		notProperInstanceOfRelations = _getNotProperInstanceOfRelations(11);	 	_status("Searching for instanceOf relations which do not exist..."); 		noInstanceOfRelations = _getNoInstanceOfRelations(13);	}	protected void _load(ObjectInputStream inputStream)		throws IOException, ClassNotFoundException {		super._load(inputStream);		explicitStatements = (List)inputStream.readObject();		noExplicitStatements = (List)inputStream.readObject();		resources = (List)inputStream.readObject();		notProperMembers = (List)inputStream.readObject();		noClasses = (List)inputStream.readObject();		noProperties = (List)inputStream.readObject();		literals = (List)inputStream.readObject();		classes = (List)inputStream.readObject();		superClasses = (List)inputStream.readObject();		directSuperClasses = (List)inputStream.readObject();		leafClasses  = (List)inputStream.readObject();		subClasses = (List)inputStream.readObject();		directSubClasses = (List)inputStream.readObject();		rootClasses = (List)inputStream.readObject();		instantiatedClasses = (List)inputStream.readObject();		properInstantiatedClasses = (List)inputStream.readObject();		notInstantiatedClasses = (List)inputStream.readObject();		notProperInstantiatedClasses = (List)inputStream.readObject();		classes2 = (List)inputStream.readObject();		properties = (List)inputStream.readObject();		superProperties = (List)inputStream.readObject();		directSuperProperties = (List)inputStream.readObject();		leafProperties = (List)inputStream.readObject();		subProperties = (List)inputStream.readObject();		directSubProperties = (List)inputStream.readObject();		rootProperties = (List)inputStream.readObject();		subClassOfRelations = (List)inputStream.readObject();		directSubClassOfRelations = (List)inputStream.readObject();		indirectSubClassOfRelations = (List)inputStream.readObject();		noSubClassOfRelations = (List)inputStream.readObject();		subPropertyOfRelations= (List)inputStream.readObject();		directSubPropertyOfRelations = (List)inputStream.readObject();		indirectSubPropertyOfRelations= (List)inputStream.readObject();		noSubPropertyOfRelations= (List)inputStream.readObject();		instanceOfRelations = (List)inputStream.readObject();		properInstanceOfRelations = (List)inputStream.readObject();		notProperInstanceOfRelations = (List)inputStream.readObject();		noInstanceOfRelations = (List)inputStream.readObject();	}	protected void _save(ObjectOutputStream outputStream)		throws IOException {		super._save(outputStream);		outputStream.writeObject(explicitStatements);		outputStream.writeObject(noExplicitStatements);		outputStream.writeObject(resources);		outputStream.writeObject(notProperMembers);		outputStream.writeObject(noClasses);		outputStream.writeObject(noProperties);		outputStream.writeObject(literals);		outputStream.writeObject(classes);		outputStream.writeObject(superClasses);		outputStream.writeObject(directSuperClasses);		outputStream.writeObject(leafClasses);		outputStream.writeObject(subClasses);		outputStream.writeObject(directSubClasses);		outputStream.writeObject(rootClasses);		outputStream.writeObject(instantiatedClasses);		outputStream.writeObject(properInstantiatedClasses);		outputStream.writeObject(notInstantiatedClasses);		outputStream.writeObject(notProperInstantiatedClasses);		outputStream.writeObject(classes2);		outputStream.writeObject(properties);		outputStream.writeObject(superProperties);		outputStream.writeObject(directSuperProperties);		outputStream.writeObject(leafProperties);		outputStream.writeObject(subProperties);		outputStream.writeObject(directSubProperties);		outputStream.writeObject(rootProperties);		outputStream.writeObject(subClassOfRelations);		outputStream.writeObject(directSubClassOfRelations);		outputStream.writeObject(indirectSubClassOfRelations);		outputStream.writeObject(noSubClassOfRelations);		outputStream.writeObject(subPropertyOfRelations);		outputStream.writeObject(directSubPropertyOfRelations);		outputStream.writeObject(indirectSubPropertyOfRelations);		outputStream.writeObject(noSubPropertyOfRelations);		outputStream.writeObject(instanceOfRelations);		outputStream.writeObject(properInstanceOfRelations);		outputStream.writeObject(notProperInstanceOfRelations);		outputStream.writeObject(noInstanceOfRelations);	}	protected List _getNoExplicitStatements(int preferredSize) {		/* 2-dimensional array containing every possible pattern of wildcards and		 * boolean indicating if object is an instance of rdfs:Resource or		 * rdfs:Literal. If object is a wildcard, object type is not relevant.		 */		boolean[][] patterns = {			{false, false, false, true}, {false, false, false, false},			{true, false, false, true}, {true, false, false, false},			{false, true, false, true}, {false, true, false, false},			{false, false, true, false}, {true, true, false, true},								/* In the current interpretation of RDF(S) every								 * literal exists as a subject. Therefore, next								 * pattern is not useful: {true, true, false,								 * false}.								 */			{true, false, true, false}, {false, true,  true, false}};		return _getNoStatements(preferredSize, patterns, true);	}	protected boolean _hasStatement(			Resource subject, URI predicate, Value object, boolean explicitOnly)	{		if (explicitOnly) {			return _rdfSchemaSource.hasExplicitStatement(subject, predicate, object);		}		else {			return _rdfSchemaSource.hasStatement(subject, predicate, object);		}	}	protected StatementIterator _getStatements(			Resource subject, URI predicate, Value object, boolean explicitOnly)	{		if (explicitOnly) {			return _rdfSchemaSource.getExplicitStatements(subject, predicate, object);		}		else {			return _rdfSchemaSource.getStatements(subject, predicate, object);		}	}	/* Creates a List of instantiated classes. Classes are distributed evenly	 * over repository. rdfs:Resource and rdfs:Literal are excluded from List.	 *	 * Optimized approach, in memory...	 */	protected List _getInstantiatedClasses		(int preferredSize, boolean mostSpecific) {		// Collect all instantiated classes.		List instantiatedClasses = new ArrayList();		Set classes = new HashSet(_classesX);		/* Exclude rdfs:Resource if mostSpecific is set to false,		 * getInstancesOf(rdfs:Resource, false) is treated as a standalone call.		 */		if (!mostSpecific) {			classes.remove(new URIImpl(RDFS.RESOURCE));		}		Iterator i = classes.iterator();		while (i.hasNext()) {			Resource classResource = (Resource)i.next();			/* Get number of proper instances or instances depending on			 * mostSpecific.			 */			int instances = 0;			if (mostSpecific) {				instances =					((Integer)_numbersOfProperInstances.get(classResource)).intValue();			}			else {				instances =					((Integer)_numbersOfInstances.get(classResource)).intValue();			}			if (instances > 0) {				// classResource has a instance.				instantiatedClasses.add(classResource);			}		}		int size = instantiatedClasses.size();		if (size == 0) {			String warning = "Repository has no ";			if (mostSpecific) {				warning += "proper ";			}			warning += "instantiated classes.";			_warning(warning);			return instantiatedClasses;		}		else {			/* Else distribute instantiated classes in instantiatedClasses over			 * new List.			 */			return _distribute(instantiatedClasses, preferredSize);		}	}	/* Creates a List of classes which are not instantiated. Classes are	 * distributed evenly over repository.	 *	 * Optimized approach, in memory...	 */	protected List _getNotInstantiatedClasses		(int preferredSize, boolean mostSpecific) {		// Collect all classes which are not instantiated.		List all = new ArrayList();		Iterator i = _classes.iterator();		while (i.hasNext()) {			Resource classResource = (Resource)i.next();			/* Get number of proper instances or instances depending on			 * mostSpecific.			 */			int instances = 0;			if (mostSpecific) {				instances =					((Integer)_numbersOfProperInstances.get(classResource)).intValue();			}			else {				instances =					((Integer)_numbersOfInstances.get(classResource)).intValue();			}			if (instances == 0) {				// classResource has no instance.				all.add(classResource);			}		}		int size = all.size();		if (size == 0) {			String warning = "Repository has no classes which are not ";			if (mostSpecific) {				warning += "proper ";			}			warning += "instantiated.";			_warning(warning);			return all;		}		else {			/* Else distribute classes which are not instantiated in all over new			 * List.			 */			return _distribute(all, preferredSize);		}	}	/* Creates a List of resources which are a indirect a member of some class.	 * Resources are distributed evenly over repository.	 *	 * Optimized approach, combination of streaming and in memory...	 */	protected List _getNotProperMembers(int preferredSize) {		// Collect all resources which are a indirect member of some class. 		List all = new ArrayList();		StatementIterator i = _rdfSchemaSource.getType(null, URIImpl.RDFS_RESOURCE);		while (i.hasNext()) {			Statement stat = i.next();			Resource resource = stat.getSubject();			if (resource instanceof URI) {				StatementIterator j = _rdfSchemaSource.getType(resource, null);				// Every resource is an instance of some class. If it is an				// instance of more than one class, it is a indirect member of				// some class.				j.next();				if (j.hasNext()) {					all.add(resource);				}				j.close();			}		}

⌨️ 快捷键说明

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