Reputation: 99
Building from the previous asked question (How can I programmatically compute path length using Jena RDF/Ontology API?), I need to multiply a numerical value (e.g. 3.5) to one of the specific class (its class size as detailed in the previous question) and be able to compute the overall path length(s) in an RDF Graph. Note that each path that fall-under this specific node will produce a new path weight result.
What I tried to do is to create a method called nValue
and passed to it the classSize
and the this numerical value variable then added it to the pathSize
method for computing the pathLength
, the method is as follows:
public static double nValue (int classWeight, double nv )
{
double numValue = classWeight*nv;
if ( nv < 1 ){
numValue = 1.0;
}
return numValue;
}
Then tried to call this method in the pathSize
method to vain. My problem is that I'm new to Jena. So I have a problem in getting a single class in an RDF graph and perform the multiplications to it and combine it to the pathLength
computation.
Upvotes: 1
Views: 95
Reputation: 85883
The code for the answer from the previous question was
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;
}
It's not exactly clear to me what it is that you're trying to do, but it sounds like you're trying to adjust the currSize
in pathSize
for certain classes (i.e., the value of returned by path.get( i )
, but that you're having trouble comparing whether or not the class is one of the classes for which this should happen. If I'm understanding correctly, you can do something like this:
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
}
// ...
}
// ...
}
Upvotes: 0