-
Notifications
You must be signed in to change notification settings - Fork 36
conversion:TemplatedTopicsEnhancement
Tim L edited this page May 22, 2015
·
10 revisions
Example that finally pushed this long-needed feature to implementation: hackerceo-org/vivo2doi (draft modeling notes)
Also done here for file format prov:alternateOfs.
https://github.com/timrdf/csv2rdf4lod-automation/issues/383
public CSVtoRDF(...
this.rowTopics = this.eParams.getRowTopics();
public Set<Resource> DefaultEnhancementParameters.getRowTopics() {
@Override
public Set<Resource> getRowTopics() {
...
for( Statement statement : Iterations.asList(conn.getStatements(null, Conversion.topic, null, false)) ) {
if( statement.getObject() instanceof Resource ) {
topics.add((Resource) statement.getObject());
}
}
...
public HashMap<URI,Set<Value>> DefaultEnhancementParameters.getTopicDescriptions(Resource topic) {
HashMap<URI,Set<Value>> descriptions = new HashMap<URI,Set<Value>>();
RepositoryConnection conn = null;
try {
conn = this.paramsRepository.getConnection();
for( Statement statement : Iterations.asList(conn.getStatements(topic, null, null, false)) ) {
if( ! descriptions.containsKey(statement.getPredicate()) ) {
descriptions.put(statement.getPredicate(), new HashSet<Value>());
}
descriptions.get(statement.getPredicate()).add(statement.getObject());
}
public void visit(CSVRecord record, long rowNum) {
...
for( Resource topic : topDownTemplate(rowTopics, primary, ancillary) ) {
if( topic instanceof URI ) {
subjects.add((URI) topic);
}
}
// "Normal" tabular-like processing is applied to the set of 'subjects'.
private Set<Resource> topDownTemplate(Resource topic,
RepositoryConnection primary,
RepositoryConnection ancillary,
String indent) {
logger.fine(indent + "topic: " + topic);
HashMap<URI, Set<Value>> descriptions = eParams.getTopicDescriptions(topic);
Set<Resource> topicRs = new HashSet<Resource>();
if( descriptions.containsKey(Conversion.name) ) {
for( Value templateV : descriptions.get(Conversion.name) ) {
logger.fine(indent+" name template: " + templateV.stringValue());
String filled = this.csvRecordFiller.fillTemplate(templateV.stringValue());
if( ResourceValueHandler.isURI(filled) ) {
topicRs.add(vf.createURI(filled));
}else {
// TODO: use ResourceValueHandler's URI creation.
topicRs.add(vf.createURI(sdv.getURIUpToVersion()+"/"+filled));
}
}
}
if( topicRs.size() == 0 ) {
topicRs.add(vf.createURI(sdv.getURIUpToVersion() + NameFactory.getUUIDName()));
}
for( Resource topicR : topicRs ) {
for( URI predicate : descriptions.keySet() ) {
if( !predicate.equals(Conversion.name) ) {
for ( Value object : descriptions.get(predicate)) {
logger.fine(indent+" " + predicate.stringValue() + " " + object.stringValue());
if( object instanceof URI ) {
try {
primary.add(topicR, predicate, object);
} catch (RepositoryException e) {
e.printStackTrace();
}
}else if( object instanceof Resource ) {
Set<Resource> objectRs = topDownTemplate((Resource) object, primary, ancillary, indent+" ");
if( objectRs != null ) {
for( Resource objectR : objectRs ) {
if( objectR instanceof URI ) {
try {
primary.add(topicR, predicate, objectR);
} catch (RepositoryException e) {
e.printStackTrace();
}
}
}
}
}
}
}
}
}