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
|
@Deprecated
|
||||||
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
|
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses, boolean getIndividualCount) {
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
|
|
||||||
|
if (getIndividualCount) {
|
||||||
|
group.setIndividualCount( getClassGroupInstanceCount(group));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((group != null) && (group.getURI() != null)) {
|
if ((group != null) && (group.getURI() != null)) {
|
||||||
Resource groupRes = ResourceFactory.createResource(group.getURI());
|
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) {
|
public void addVClassesToGroups(List <VClassGroup> groups) {
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -68,31 +68,25 @@ public class VClassDaoSDB extends VClassDaoJena {
|
||||||
VClass vcw = (VClass) getVClassByURI(cls.getURI());
|
VClass vcw = (VClass) getVClassByURI(cls.getURI());
|
||||||
if (vcw != null) {
|
if (vcw != null) {
|
||||||
boolean classIsInstantiated = false;
|
boolean classIsInstantiated = false;
|
||||||
if (getIndividualCount) {
|
if (getIndividualCount) {
|
||||||
Model aboxModel = getOntModelSelector().getABoxModel();
|
int count = 0;
|
||||||
aboxModel.enterCriticalSection(Lock.READ);
|
String[] graphVars = { "?g" };
|
||||||
int count = 0;
|
String countQueryStr = "SELECT COUNT(DISTINCT ?s) WHERE \n" +
|
||||||
try {
|
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
|
||||||
String[] graphVars = { "?g" };
|
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
|
||||||
String countQueryStr = "SELECT COUNT(DISTINCT ?s) WHERE \n" +
|
"} \n";
|
||||||
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
|
Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ);
|
||||||
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
|
DatasetWrapper w = getDatasetWrapper();
|
||||||
"} \n";
|
Dataset dataset = w.getDataset();
|
||||||
Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
DatasetWrapper w = getDatasetWrapper();
|
try {
|
||||||
Dataset dataset = w.getDataset();
|
QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset);
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
ResultSet rs = qe.execSelect();
|
||||||
try {
|
count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
|
||||||
QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset);
|
} finally {
|
||||||
ResultSet rs = qe.execSelect();
|
dataset.getLock().leaveCriticalSection();
|
||||||
count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm());
|
w.close();
|
||||||
} finally {
|
}
|
||||||
dataset.getLock().leaveCriticalSection();
|
|
||||||
w.close();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
aboxModel.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
vcw.setEntityCount(count);
|
vcw.setEntityCount(count);
|
||||||
classIsInstantiated = (count > 0);
|
classIsInstantiated = (count > 0);
|
||||||
} else if (includeUninstantiatedClasses == false) {
|
} else if (includeUninstantiatedClasses == false) {
|
||||||
|
@ -137,6 +131,7 @@ public class VClassDaoSDB extends VClassDaoJena {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
int getClassGroupInstanceCount(VClassGroup vcg){
|
int getClassGroupInstanceCount(VClassGroup vcg){
|
||||||
int count = 0;
|
int count = 0;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -157,9 +157,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
||||||
groups.add(ungrouped);
|
groups.add(ungrouped);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (groups.size()>0) {
|
if (groups.size()>0) {
|
||||||
// if( getIndividualCount )
|
|
||||||
// addIndividualCountToGroups(groups);
|
|
||||||
return groups;
|
return groups;
|
||||||
} else {
|
} else {
|
||||||
/* bdc34: the effect of the following code is that
|
/* bdc34: the effect of the following code is that
|
||||||
|
@ -168,9 +166,7 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
|
||||||
* the vclasses are empty.
|
* the vclasses are empty.
|
||||||
* This may not be the desired behavior.
|
* This may not be the desired behavior.
|
||||||
*/
|
*/
|
||||||
classDao.addVClassesToGroups(groups);
|
classDao.addVClassesToGroups(groups);
|
||||||
if( getIndividualCount )
|
|
||||||
addIndividualCountToGroups(groups);
|
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
} finally {
|
} 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) {
|
public VClassGroup groupFromGroupIndividual(Individual groupInd) {
|
||||||
if (groupInd==null) {
|
if (groupInd==null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue