Fixing bug with zero individual counts for class groups. NIHVIVO-1893
This commit is contained in:
parent
d6f19324f8
commit
34258ae94b
3 changed files with 50 additions and 81 deletions
|
@ -780,6 +780,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
@Deprecated
|
||||
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
|
||||
getOntModel().enterCriticalSection(Lock.READ);
|
||||
|
||||
if (getIndividualCount) {
|
||||
group.setIndividualCount( getClassGroupInstanceCount(group));
|
||||
}
|
||||
|
||||
try {
|
||||
if ((group != null) && (group.getURI() != null)) {
|
||||
Resource groupRes = ResourceFactory.createResource(group.getURI());
|
||||
|
@ -847,6 +852,29 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
}
|
||||
}
|
||||
|
||||
int getClassGroupInstanceCount(VClassGroup vcg){
|
||||
Model ontModel = getOntModel();
|
||||
ontModel.enterCriticalSection(Lock.READ);
|
||||
int count = 0;
|
||||
try {
|
||||
String queryText =
|
||||
"SELECT COUNT( DISTINCT ?instance ) WHERE { \n" +
|
||||
" ?class <"+VitroVocabulary.IN_CLASSGROUP+"> <"+vcg.getURI() +"> .\n" +
|
||||
" ?instance a ?class . \n" +
|
||||
"}" ;
|
||||
Query countQuery = QueryFactory.create(queryText, Syntax.syntaxARQ);
|
||||
QueryExecution qe = QueryExecutionFactory.create(countQuery, ontModel);
|
||||
ResultSet rs =qe.execSelect();
|
||||
count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
|
||||
}catch(Exception ex){
|
||||
log.error(ex,ex);
|
||||
} finally {
|
||||
ontModel.leaveCriticalSection();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public void addVClassesToGroups(List <VClassGroup> groups) {
|
||||
getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
|
|
|
@ -69,10 +69,7 @@ public class VClassDaoSDB extends VClassDaoJena {
|
|||
if (vcw != null) {
|
||||
boolean classIsInstantiated = false;
|
||||
if (getIndividualCount) {
|
||||
Model aboxModel = getOntModelSelector().getABoxModel();
|
||||
aboxModel.enterCriticalSection(Lock.READ);
|
||||
int count = 0;
|
||||
try {
|
||||
String[] graphVars = { "?g" };
|
||||
String countQueryStr = "SELECT COUNT(DISTINCT ?s) WHERE \n" +
|
||||
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
|
||||
|
@ -90,9 +87,6 @@ public class VClassDaoSDB extends VClassDaoJena {
|
|||
dataset.getLock().leaveCriticalSection();
|
||||
w.close();
|
||||
}
|
||||
} finally {
|
||||
aboxModel.leaveCriticalSection();
|
||||
}
|
||||
vcw.setEntityCount(count);
|
||||
classIsInstantiated = (count > 0);
|
||||
} else if (includeUninstantiatedClasses == false) {
|
||||
|
@ -137,6 +131,7 @@ public class VClassDaoSDB extends VClassDaoJena {
|
|||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
int getClassGroupInstanceCount(VClassGroup vcg){
|
||||
int count = 0;
|
||||
try {
|
||||
|
|
|
@ -158,8 +158,6 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
}
|
||||
*/
|
||||
if (groups.size()>0) {
|
||||
// if( getIndividualCount )
|
||||
// addIndividualCountToGroups(groups);
|
||||
return groups;
|
||||
} else {
|
||||
/* bdc34: the effect of the following code is that
|
||||
|
@ -169,8 +167,6 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
* This may not be the desired behavior.
|
||||
*/
|
||||
classDao.addVClassesToGroups(groups);
|
||||
if( getIndividualCount )
|
||||
addIndividualCountToGroups(groups);
|
||||
return groups;
|
||||
}
|
||||
} finally {
|
||||
|
@ -179,56 +175,6 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
|||
|
||||
}
|
||||
|
||||
protected void addIndividualCountToGroups( List<VClassGroup> cgList ){
|
||||
for( VClassGroup cg : cgList){
|
||||
int count = 0;
|
||||
for( VClass vc : cg){
|
||||
count = count + vc.getEntityCount();
|
||||
}
|
||||
cg.setIndividualCount(count);
|
||||
}
|
||||
}
|
||||
|
||||
// private int individuialCountForGroup( VClassGroup vcg){
|
||||
// int count = 0;
|
||||
// try{
|
||||
// Model aboxModel = getOntModelSelector().getABoxModel();
|
||||
// aboxModel.enterCriticalSection(Lock.READ);
|
||||
// try {
|
||||
//
|
||||
// String[] graphVars = { "?g" };
|
||||
// String countQueryStr = "SELECT COUNT(DISTINCT ?s) WHERE \n" +
|
||||
// "{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
|
||||
// WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
|
||||
// "} \n";
|
||||
// Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ);
|
||||
// DatasetWrapper w = getDatasetWrapper();
|
||||
// Dataset dataset = w.getDataset();
|
||||
// dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
// try {
|
||||
// QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset);
|
||||
// ResultSet rs = qe.execSelect();
|
||||
// count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
|
||||
// } finally {
|
||||
// dataset.getLock().leaveCriticalSection();
|
||||
// w.close();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//// String countQueryStr = "SELECT COUNT(*) WHERE \n" +
|
||||
//// "{ ?s a <" + cls.getURI() + "> } ";
|
||||
//// Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ);
|
||||
//// QueryExecution qe = QueryExecutionFactory.create(countQuery, aboxModel);
|
||||
//// ResultSet rs =qe.execSelect();
|
||||
//// count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
|
||||
// } finally {
|
||||
// aboxModel.leaveCriticalSection();
|
||||
// }
|
||||
// }catch(Exception ex){
|
||||
// log.debug("error during individuialCountForGroup()", ex);
|
||||
// }
|
||||
// return count;
|
||||
// }
|
||||
|
||||
public VClassGroup groupFromGroupIndividual(Individual groupInd) {
|
||||
if (groupInd==null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue