上一个问题的答案代码是
public static int classSize( final Resource klass ) {
return klass.getModel().listSubjectsWithProperty( RDFS.subClassOf, klass ).toList().size();
}
public static double pathSize( final List<Resource> path ) {
int prevSize = classSize( path.get( 0 ));
double pathSum = prevSize;
for ( int i = 1; i < path.size(); i++ ) {
int currSize = classSize( path.get( i ));
double linkWeight = currSize < prevSize ? 0.5 : 1.0;
pathSum += linkWeight + currSize;
prevSize = currSize;
}
return pathSum;
}
我不清楚您要做什么,但听起来您正在尝试调整某些类的currSize
in pathSize
(即,返回的值 by path.get( i )
,但是您在比较是否该课程是否是应该发生这种情况的课程之一。如果我理解正确,您可以执行以下操作:
private static Resource specialClass = ResourceFactory.createResource( "http://.../specialClass" );
public static double pathSize( final List<Resource> path ) {
// ...
for ( int i = 1; i < path.size(); i++ ) {
final Resource klass = path.get( i );
int currSize = classSize( klass );
if ( specialClass.equals( klass ) ) { // When klass is specialClass
currSize = ...; // something different // do the additional modification
}
// ...
}
// ...
}