Commit 52ffdc59 authored by Richard Bruskiewich's avatar Richard Bruskiewich

Turtle RDF for crops, traits, trait categories and methods is fully

functional (as far as I can tell, for the moment).
parent ed9492f4
......@@ -30,6 +30,7 @@ import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import org.genesys2.server.model.impl.Crop;
......@@ -43,6 +44,9 @@ import org.bioversityinternational.model.rdf.dwc.DarwinCore;
@RequestMapping(value = "/crops", method = RequestMethod.GET, headers = "accept=text/turtle", produces = RdfBaseController.RDF_MEDIATYPE_TURTLE)
public class CropControllerRdf extends RdfBaseController {
public static final String CROPS_NS = getBaseUri()+"/crops/";;
public static final String SPECIES_NS = CROPS_NS+"species/" ;
@Autowired
private CropService cropService;
......@@ -51,7 +55,7 @@ public class CropControllerRdf extends RdfBaseController {
*
* Crop RDF exemplar:
*
cco:MusaTaxon a dwc:Taxon, skos:Collection;
genesys:MusaTaxon a dwc:Taxon, skos:Collection;
dwc:scientificName "Musa" ;
dwc:vernacularName "Musa"@en ;
dwc:vernacularName "Musa"@es ;
......@@ -65,26 +69,15 @@ public class CropControllerRdf extends RdfBaseController {
dc:creator "Bioversity International" ;
skos:member cco:MusaAcuminata, cco:MusaBalbisiana
.
cco:MusaAcuminata a cco:Species;
dwc:scientificName "Musa acuminata" ;
dwc:genus "Musa" ;
dc:description "Wild progenitor of domesticated bananas."@en ;
dc:description "Progenitor salvaje de plátanos domesticados."@es ;
dc:description "Дикий прародителем домашних бананов."@ru ;
dc:description "香蕉驯化野生祖。"@zh ;
cco:speciesIncluded "true"
.
*/
*/
private void wrapCrop(Model model, Crop crop) {
Resource subject = createSubject(model, crop, CCO.getURI()+crop.getId(), crop.getShortName()+" Taxon") ;
subject.addProperty(DarwinCore.scientificName, crop.getShortName()) ;
Resource cropSubj = createSubject(model, crop, CROPS_NS+crop.getId(), crop.getShortName()+" Taxon") ;
cropSubj.addProperty(DarwinCore.scientificName, crop.getShortName()) ;
String seeAlso = crop.getRdfUri() ;
if(seeAlso!=null)
subject.addProperty(
cropSubj.addProperty(
RDFS.seeAlso,
model.createResource(seeAlso)
) ;
......@@ -98,7 +91,7 @@ public class CropControllerRdf extends RdfBaseController {
for( String language : vernacularNameMap.keySet() ) {
Literal vernacularNameLiteral =
model.createLiteral(vernacularNameMap.get(language), language) ;
subject.addLiteral(DarwinCore.vernacularName,vernacularNameLiteral) ;
cropSubj.addLiteral(DarwinCore.vernacularName,vernacularNameLiteral) ;
}
else
this._logger.warn("Empty vernacular crop name map for crop "+crop.getShortName());
......@@ -109,17 +102,43 @@ public class CropControllerRdf extends RdfBaseController {
for( String language : vernacularDefinitionMap.keySet() ) {
Literal vernacularDefinitionLiteral =
model.createLiteral(vernacularDefinitionMap.get(language), language) ;
subject.addLiteral(DC.description,vernacularDefinitionLiteral) ;
cropSubj.addLiteral(DC.description,vernacularDefinitionLiteral) ;
}
else
this._logger.warn("Empty vernacular crop description map for crop "+crop.getShortName());
/* Exemplar for CropRule species...
*
genesys:MusaAcuminata a cco:Species;
dwc:scientificName "Musa acuminata" ;
dwc:genus "Musa" ;
dc:description "Wild progenitor of domesticated bananas."@en ;
dc:description "Progenitor salvaje de plátanos domesticados."@es ;
dc:description "Дикий прародителем домашних бананов."@ru ;
dc:description "香蕉驯化野生祖。"@zh ;
cco:speciesIncluded "true"
.
Note: current GENESYS data model does NOT track the description of a species...
*/
List<CropRule> rules = cropService.getCropRules(crop) ;
for(CropRule cr : rules) {
String species = cr.getSpecies() ;
String genus = cr.getGenus() ;
Boolean isIncluded = cr.isIncluded() ;
Boolean isIncluded = cr.isIncluded() ;
Resource speciesSubj =
createSubject(
model,
crop,
SPECIES_NS+canonicalID(species,true),
species
) ;
speciesSubj.addProperty(RDF.type, CCO.Species ) ;
speciesSubj.addProperty(DarwinCore.scientificName, species ) ;
speciesSubj.addProperty(DarwinCore.genus, genus ) ;
speciesSubj.addProperty(CCO.speciesIncluded, isIncluded.toString() ) ;
}
}
......
......@@ -95,25 +95,28 @@ public abstract class RdfBaseController extends BaseController {
}
/**
* Generates a Camel cased identifier from its imput string
* Generates a canonical RDF identifier from its input string
* (blanks removed, with title case or camel case words, depending
* on capitalizeFirst being true or false, respectively)
*
* @param s
* @param identifier
* @param capitlizeFirst - if true, then the first letter of the identifier is capitalized
* @return
*/
private static String TitleCase(String s, Boolean capitalizeFirst) {
String[] words = s.split("\\s") ;
s = "" ;
public static String canonicalID(String identifier, Boolean capitalizeFirst) {
String[] words = identifier.split("\\s") ;
identifier = "" ;
for(String word: words) {
if(!capitalizeFirst) {
// only run once in the loop if false (reset to true...)
s += word.toLowerCase() ;
identifier += word.toLowerCase() ;
capitalizeFirst = true ;
} else {
s += word.substring(0,1).toUpperCase() ;
s += word.substring(1).toLowerCase() ;
identifier += word.substring(0,1).toUpperCase() ;
identifier += word.substring(1).toLowerCase() ;
}
}
return s ;
return identifier ;
}
/*
......@@ -150,9 +153,9 @@ public abstract class RdfBaseController extends BaseController {
subject.addProperty(RDF.type, SKOS.Concept) ;
if(isProperty)
tag= TitleCase(tag,false) ;
tag= canonicalID(tag,false) ;
else
tag = TitleCase(tag,true) ;
tag = canonicalID(tag,true) ;
subject.addProperty(SKOS.hiddenLabel,tag) ;
// dc:creator <user>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment