📄 rdfschemasourcepool.java
字号:
// classes minus subClasses of class. Set noSubClasses = new HashSet(_classes); // Get subClasses. noSubClasses.removeAll((List)_subClasses.get(classResource)); Iterator k = noSubClasses.iterator(); while (k.hasNext()) { distributed.add(new Binary(_stripId((Resource)k.next()), _stripId(classResource))); } } } else { // This algorithm only connects to repository if current class // iterator returns has subClassOf relations which do not exist on // interval and skips rest. // Position of next subClassOf relation which does not exist. int position = 0; double lookAhead = 0; while (j.hasNext()) { Resource classResource = (Resource)j.next(); // Get number of classes which are not a subClass. int numberOfNoSubClasses = ((Integer)numbersOfNoSubClasses.get(classResource)).intValue(); // Look ahead. lookAhead = lookAhead + numberOfNoSubClasses; if (lookAhead > interval || position == totalNoSubClassOf - numberOfNoSubClasses) { // Class has subClassOf relations which do not exist on // interval, connect to repository. Set noSubClasses = new HashSet(_classes); // Get subClasses. noSubClasses.removeAll((List)_subClasses.get(classResource)); Iterator k = noSubClasses.iterator(); while(k.hasNext()) { position++; // Computation of last position modulo interval should be // zero and therefore last subClassOf relation which does // not exist should be added to distributed. Because of // possible loss of precision, computation could fail and // last subClassOf relation which does not exist wille // 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 == totalNoSubClassOf) { // Position on interval. distributed.add (new Binary(_stripId((Resource)k.next()), _stripId(classResource))); } else { k.next(); } } lookAhead = lookAhead % interval; } else { // Skip class. position += numberOfNoSubClasses; } } } return distributed; } /* Creates a List of subPropertyOf relations represented by object * Binary with size is preferredSize. Each Binary represents * two properties which are NOT a subProperty of eachother. SubPropertyOf * relations are distributed evenly over repository. * * Optimized approach, a combination of streaming and in memory... */ protected List _getNoSubPropertyOfRelations(int preferredSize) { /* For each property, count number of properties which are not a * subProperty of property. Also count total number of subPropertyOf * relations which do not exist. Number of properties which are not a * subProperty of property is equal to total number of properties minus * number of subProperties of property. */ Map numbersOfNoSubProperties = new HashMap(); int totalNoSubPropertyOf = 0; int numberOfProperties = _properties.size(); Iterator i = _properties.iterator(); while (i.hasNext()) { Resource superProperty = (Resource)i.next(); // Get number of subProperties. int subProperties = ((Integer)_numbersOfSubProperties.get(superProperty)).intValue(); int noSubProperties = numberOfProperties - subProperties; totalNoSubPropertyOf += noSubProperties; /* Save number of properties which are not a subProperty of this * property. */ numbersOfNoSubProperties.put (superProperty, new Integer(noSubProperties)); } List distributed = new ArrayList(); if (totalNoSubPropertyOf == 0) { _warning("Repository has no subPropertyOf relations which do not exist."); return distributed; } /* Compute interval on which subPropertyOf relations which do not exist * are retrieved. */ double interval = (double)totalNoSubPropertyOf/preferredSize; /* Iterate over all properties and construct and add Binary * object representing a subPropertyOf relation which does exist to * distributed if on interval. */ Iterator j = _properties.iterator(); /* If interval is smaller than or equal to one then preferredSize is * equal to or exceeds totalNoSubPropertyOf and distributed is equal to * all subPropertyOf relations which do not exist. Else relations are * distributed evenly. */ if (interval <= 1) { while (j.hasNext()) { Resource property = (Resource)j.next(); /* Properties which are not a subProperty of property are equal * to all properties minus subProperties of property. */ Set noSubProperties = new HashSet(_properties); // Get subProperties. noSubProperties.removeAll((List)_subProperties.get(property)); Iterator k = noSubProperties.iterator(); while (k.hasNext()) { distributed.add(new Binary(_stripId((Resource)k.next()), _stripId(property))); } } } else { /* This algorithm only connects to repository if current property * iterator returns has subPropertyOf relations which do not exist on * interval and skips rest. * * Position of next subPropertyOf relation which does not exist. */ int position = 0; double lookAhead = 0; while (j.hasNext()) { Resource property = (Resource)j.next(); // Get number of properties which are not a subProperty. int numberOfNoSubProperties = ((Integer)numbersOfNoSubProperties.get(property)).intValue(); // Look ahead. lookAhead = lookAhead + numberOfNoSubProperties; if (lookAhead > interval || position == totalNoSubPropertyOf - numberOfNoSubProperties) { /* Property has subPropertyOf relations which do not exist on * interval, connect to repository. */ Set noSubProperties = new HashSet(_properties); // Get subProperties. noSubProperties.removeAll((List)_subProperties.get(property)); Iterator k = noSubProperties.iterator(); while(k.hasNext()) { position++; /* Computation of last position modulo interval should be * zero and therefore last subPropertyOf relation which * does not exist should be added to distributed. Because * of possible loss of precision, computation could fail * and last subPropertyOf relation which does not exist * 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 == totalNoSubPropertyOf) { // Position on interval. distributed.add (new Binary(_stripId((Resource)k.next()), _stripId(property))); } else { k.next(); } } lookAhead = lookAhead % interval; } else { // Skip property. position += numberOfNoSubProperties; } } } return distributed; } /* Creates a List of instanceOf relations represented by object Binary with * size is preferredSize. Each Binary represents a resource and a class which * are NOT an instance of eachother. InstanceOf relations are distributed * evenly over repository. * * Optimized approach, a combination of streaming and in memory... */ protected List _getNoInstanceOfRelations(int preferredSize) { /* For each class, count number of resources which are not an instance of * class. Also count total number of instanceOf relations which do not * exist. Number of resources which are not an instance of class is equal * to total number of resources minus number of instances of class. */ Map numbersOfNoInstanceOf = new HashMap(); int totalNoInstanceOf = 0; int resources = ((Integer)_numbersOfInstances.get(new URIImpl(RDFS.RESOURCE))).intValue(); Iterator i = _classesX.iterator(); while (i.hasNext()) { Resource classResource = (Resource)i.next(); // Get number of instances. int noInstanceOf = resources - ((Integer)_numbersOfInstances.get(classResource)).intValue(); totalNoInstanceOf += noInstanceOf; // Save number of resources which are not an instance of this class. numbersOfNoInstanceOf.put(classResource, new Integer(noInstanceOf)); } List distributed = new ArrayList(); if (totalNoInstanceOf == 0) { _warning("Repository has no instanceOf relations which do not exist."); return distributed; } /* Compute interval on which instanceOf relations which do not exist * are retrieved. */ double interval = (double)totalNoInstanceOf/preferredSize; /* Iterate over all classes and construct and add Binary object * representing an instanceOf relation which does exist 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 totalNoInstanceOf and distributed is equal to all * instanceOf relations which do not exist. Else relations are * distributed evenly. */ if (interval <= 1) { while (j.hasNext()) { Resource classResource = (Resource)j.next(); /* Resources which are not an instance of class are equal to all * resources minus instances of class. */ Set instances = _toSet( _rdfSchemaSource.getType(null, classResource)); StatementIterator k = _rdfSchemaSource.getType(null, URIImpl.RDFS_RESOURCE); while (k.hasNext()) { Resource resource = k.next().getSubject(); if (resource instanceof URI && !instances.contains(resource)) { // Resource is not an instance of class. distributed.add(new Binary( _stripId(classResource), _stripId(resource))); } } k.close(); } } else { /* This algorithm only connects to repository if current class * iterator returns has subClassOf relations which do not exist on * interval and skips rest. * * Position of next instanceOf relation which does not exist. */ int position = 0; double lookAhead = 0; while (j.hasNext()) { Resource classResource = (Resource)j.next(); // Get number of resources which are not an instance. int numberOfNoInstanceOf = ((Integer)numbersOfNoInstanceOf.get(classResource)).intValue(); // Look ahead. lookAhead = lookAhead + numberOfNoInstanceOf; if (lookAhead >= interval || position == totalNoInstanceOf - numberOfNoInstanceOf) { /* Class has instanceOf relations which do not exist on * interval, connect to repository. */ Set instances = _toSet( _rdfSchemaSource.getType(null, classResource)); StatementIterator k = _rdfSchemaSource.getType(null, URIImpl.RDFS_RESOURCE); while(k.hasNext()) { Resource resource = k.next().getSubject(); if (resource instanceof URI && !instances.contains(resource)) { // Resource is not an instance of class. position++; /* Computation of last position modulo interval * should be zero and therefore last subClassOf * relation which does not exist should be added to * distributed. Because of possible loss of * precision, computation could fail and last * subClassOf relation which does not exist 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 == totalNoInstanceOf) // Position on interval. distributed.add (new Binary(_stripId(resource), _stripId(classResource))); } } k.close(); lookAhead = lookAhead % interval; } else { // Skip class. position += numberOfNoInstanceOf; } } } return distributed; } /* Creates a List of classes which can be instantiated by a resource. * Classes in List are distributed evenly over repository. */ protected List _getClassesX(int preferredSize) { int size = _classesX.size(); if (size == 0) { _warning ("Repository has no classes which can be instantiated by some resource."); return new ArrayList(_classesX); } else { // Else distribute classes in all over new List. return _distribute(_classesX, preferredSize); } } /* Creates a List of classes retrieved from repository with size is * preferredSize. Classes in List are distributed evenly over repository. */ protected List _getClasses(int preferredSize) { int size = _classes.size(); if (size == 0) { _warning("Repository has no classes."); return new ArrayList(_classes); } else { // Else distribute classes in _classes over new List. return _distribute(_classes, preferredSize); } } /* Creates a List of properties retrieved from repository with size is * preferredSize. Properties in List are distributed evenly over repository. */ protected List _getProperties(int preferredSize) { int size = _properties.size(); if (size == 0) { _warning("Repository has no properties."); return new ArrayList(_properties); } else { // Else distribute properties in allProperties over new List. return _distribute(_properties, preferredSize); } } /* Creates a List of resources retrieved from repository which are not a * class with size is preferredSize. Resources are d
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -