use of org.nextprot.api.rdf.domain.TripleInfo in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method getRdfTypeFullInfoList.
@Cacheable("rdfhelp")
@Override
public synchronized List<RdfTypeInfo> getRdfTypeFullInfoList() {
long t0 = System.currentTimeMillis();
Set<String> rdfTypesNames = getRdfTypesNames();
List<Future<RdfTypeInfo>> rdfFutureTypes = new ArrayList<Future<RdfTypeInfo>>();
List<RdfTypeInfo> rdfTypes = Collections.synchronizedList(new ArrayList<RdfTypeInfo>());
ExecutorService executor = Executors.newFixedThreadPool(NUMBER_THREADS);
for (String rdfTypeName : rdfTypesNames) {
// LOGGER.info("step1 - found rdf:type name " + rdfTypeName);
Future<RdfTypeInfo> futureRdfTypeInfo = executor.submit(new FillRdfTypeInfoTask(this, rdfTypeName));
rdfFutureTypes.add(futureRdfTypeInfo);
}
executor.shutdown();
try {
executor.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
e.printStackTrace();
throw new NextProtException(e.getLocalizedMessage());
}
for (Future<RdfTypeInfo> futureRdfTypeInfo : rdfFutureTypes) {
try {
rdfTypes.add(futureRdfTypeInfo.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
// now populate parent and parent triples of each type
for (RdfTypeInfo rti : rdfTypes) {
// LOGGER.info("step2 - updating rdf:type " + rti.getTypeName());
for (RdfTypeInfo parent : rdfTypes) {
List<TripleInfo> triples = parent.findTriplesWithObjectType(rti.getTypeName());
if (triples.size() > 0) {
// LOGGER.info("step3 - linking parent rdf:type " + parent.getTypeName() + " to rdf:type " + rti.getTypeName() + " , triple size: " + triples.size());
rti.addParent(parent.getTypeName());
for (TripleInfo triple : triples) rti.addParentTriple(triple);
}
}
}
Map<String, RdfTypeInfo> fullMap = new HashMap<String, RdfTypeInfo>();
for (RdfTypeInfo rti : rdfTypes) {
fullMap.put(rti.getTypeName(), rti);
}
if (fullMap.containsKey(":Entry"))
buildPathToOrigin(fullMap, fullMap.get(":Entry"), "?entry ", 0);
long seconds = (System.currentTimeMillis() - t0) / 1000;
String duration = String.format("%d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60)) + " [H:MM:SS]";
LOGGER.info("errors: " + errorCount);
LOGGER.info("duration: " + duration);
return rdfTypes;
}
use of org.nextprot.api.rdf.domain.TripleInfo in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method buildPathToOrigin.
private static void buildPathToOrigin(final Map<String, RdfTypeInfo> fullMap, RdfTypeInfo currentEntry, String currentPath, int currenDepth) {
if (currenDepth > 20)
return;
for (TripleInfo childTripleInfo : currentEntry.getTriples()) {
RdfTypeInfo childTypeInfo = fullMap.get(childTripleInfo.getObjectType());
if (childTypeInfo != null && !currentPath.contains(childTripleInfo.getPredicate()) && !childTripleInfo.getPredicate().equals(":interaction")) {
String nextPath = currentPath + childTripleInfo.getPredicate();
childTypeInfo.addPathToOrigin(nextPath);
buildPathToOrigin(fullMap, childTypeInfo, nextPath + "/", currenDepth + 1);
}
}
}
use of org.nextprot.api.rdf.domain.TripleInfo in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method getTripleInfoList.
@Override
public List<TripleInfo> getTripleInfoList(String rdfType) {
String queryBase = sparqlDictionary.getSparqlWithPrefixes("typepred");
Set<TripleInfo> tripleList = new TreeSet<TripleInfo>();
try {
String query = sparqlDictionary.getSparqlOnly("prefix");
query += queryBase.replace(":SomeRdfType", rdfType);
QueryExecution qExec = sparqlService.queryExecution(query);
ResultSet rs = qExec.execSelect();
while (rs.hasNext()) {
QuerySolution sol = rs.next();
TripleInfo ti = new TripleInfo();
String pred = (String) getDataFromSolutionVar(sol, "pred");
String sspl = (String) getDataFromSolutionVar(sol, "subjSample");
String ospl = (String) getDataFromSolutionVar(sol, "objSample", true);
String spl = sspl + " " + pred + " " + ospl + " .";
ti.setTripleSample(spl);
ti.setPredicate(pred);
ti.setSubjectType((String) getDataFromSolutionVar(sol, "subjType"));
String objectType = (String) getDataFromSolutionVar(sol, "objType");
if (objectType.length() == 0) {
objectType = getObjectTypeFromSample(sol, "objSample");
ti.setLiteralType(true);
}
ti.setObjectType(objectType);
ti.setTripleCount(Integer.valueOf((String) getDataFromSolutionVar(sol, "objCount")));
LOGGER.info(ti);
tripleList.add(ti);
}
qExec.close();
} catch (Exception e) {
incrementErrors();
System.err.println("Error with " + rdfType);
e.printStackTrace();
LOGGER.error("Error with " + rdfType, e);
}
return new ArrayList<TripleInfo>(tripleList);
}
use of org.nextprot.api.rdf.domain.TripleInfo in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method getRdfTypeFullInfo.
@Override
public RdfTypeInfo getRdfTypeFullInfo(String rdfTypeName) {
RdfTypeInfo rdfTypeInfo = new RdfTypeInfo();
rdfTypeInfo.setTypeName(rdfTypeName);
Map<String, String> properties = getRdfTypeProperties(rdfTypeName);
if (!properties.isEmpty()) {
rdfTypeInfo.setTypeName(properties.get("rdfType"));
rdfTypeInfo.setRdfsLabel(properties.get("label"));
rdfTypeInfo.setRdfsComment(properties.get("comment"));
rdfTypeInfo.setInstanceCount(Integer.valueOf(properties.get("instanceCount")));
rdfTypeInfo.setInstanceSample(properties.get("instanceSample"));
}
List<TripleInfo> triples = getTripleInfoList(rdfTypeInfo.getTypeName());
Set<String> values = null;
if (completeSetOfValuesForTypes.contains(rdfTypeInfo.getTypeName())) {
values = getRdfTypeValues(rdfTypeName, Integer.MAX_VALUE);
} else {
values = getRdfTypeValues(rdfTypeName, 20);
}
rdfTypeInfo.setValues(values);
for (TripleInfo triple : triples) {
rdfTypeInfo.addTriple(triple);
if (triple.isLiteralType() && (!triple.getObjectType().equals(RdfConstants.BLANK_OBJECT_TYPE))) {
String typeLiteral = rdfTypeName + "/" + triple.getPredicate();
Set<String> exampleValues = null;
if (completeSetOfValuesForLiteral.contains(typeLiteral)) {
exampleValues = getValuesForTriple(rdfTypeName, triple.getPredicate(), Integer.MAX_VALUE);
} else {
exampleValues = getValuesForTriple(rdfTypeName, triple.getPredicate(), 50);
}
triple.setValues(exampleValues);
}
}
return rdfTypeInfo;
}
Aggregations