Commit 04980747 authored by Richard Bruskiewich's avatar Richard Bruskiewich Committed by Matija Obreza

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

functional (as far as I can tell, for the moment).
parent 2e915b07
...@@ -30,6 +30,7 @@ import com.hp.hpl.jena.rdf.model.Literal; ...@@ -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.Model;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.DC; import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
...@@ -43,6 +44,9 @@ import org.bioversityinternational.model.rdf.dwc.DarwinCore; ...@@ -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) @RequestMapping(value = "/crops", method = RequestMethod.GET, headers = "accept=text/turtle", produces = RdfBaseController.RDF_MEDIATYPE_TURTLE)
public class CropControllerRdf extends RdfBaseController { public class CropControllerRdf extends RdfBaseController {
public static final String CROPS_NS = getBaseUri()+"/crops/";;
public static final String SPECIES_NS = CROPS_NS+"species/" ;
@Autowired @Autowired
private CropService cropService; private CropService cropService;
...@@ -51,7 +55,7 @@ public class CropControllerRdf extends RdfBaseController { ...@@ -51,7 +55,7 @@ public class CropControllerRdf extends RdfBaseController {
* *
* Crop RDF exemplar: * Crop RDF exemplar:
* *
cco:MusaTaxon a dwc:Taxon, skos:Collection; genesys:MusaTaxon a dwc:Taxon, skos:Collection;
dwc:scientificName "Musa" ; dwc:scientificName "Musa" ;
dwc:vernacularName "Musa"@en ; dwc:vernacularName "Musa"@en ;
dwc:vernacularName "Musa"@es ; dwc:vernacularName "Musa"@es ;
...@@ -65,26 +69,15 @@ public class CropControllerRdf extends RdfBaseController { ...@@ -65,26 +69,15 @@ public class CropControllerRdf extends RdfBaseController {
dc:creator "Bioversity International" ; dc:creator "Bioversity International" ;
skos:member cco:MusaAcuminata, cco:MusaBalbisiana 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) { private void wrapCrop(Model model, Crop crop) {
Resource subject = createSubject(model, crop, CCO.getURI()+crop.getId(), crop.getShortName()+" Taxon") ; Resource cropSubj = createSubject(model, crop, CROPS_NS+crop.getId(), crop.getShortName()+" Taxon") ;
subject.addProperty(DarwinCore.scientificName, crop.getShortName()) ; cropSubj.addProperty(DarwinCore.scientificName, crop.getShortName()) ;
String seeAlso = crop.getRdfUri() ; String seeAlso = crop.getRdfUri() ;
if(seeAlso!=null) if(seeAlso!=null)
subject.addProperty( cropSubj.addProperty(
RDFS.seeAlso, RDFS.seeAlso,
model.createResource(seeAlso) model.createResource(seeAlso)
) ; ) ;
...@@ -98,7 +91,7 @@ public class CropControllerRdf extends RdfBaseController { ...@@ -98,7 +91,7 @@ public class CropControllerRdf extends RdfBaseController {
for( String language : vernacularNameMap.keySet() ) { for( String language : vernacularNameMap.keySet() ) {
Literal vernacularNameLiteral = Literal vernacularNameLiteral =
model.createLiteral(vernacularNameMap.get(language), language) ; model.createLiteral(vernacularNameMap.get(language), language) ;
subject.addLiteral(DarwinCore.vernacularName,vernacularNameLiteral) ; cropSubj.addLiteral(DarwinCore.vernacularName,vernacularNameLiteral) ;
} }
else else
this._logger.warn("Empty vernacular crop name map for crop "+crop.getShortName()); this._logger.warn("Empty vernacular crop name map for crop "+crop.getShortName());
...@@ -109,17 +102,43 @@ public class CropControllerRdf extends RdfBaseController { ...@@ -109,17 +102,43 @@ public class CropControllerRdf extends RdfBaseController {
for( String language : vernacularDefinitionMap.keySet() ) { for( String language : vernacularDefinitionMap.keySet() ) {
Literal vernacularDefinitionLiteral = Literal vernacularDefinitionLiteral =
model.createLiteral(vernacularDefinitionMap.get(language), language) ; model.createLiteral(vernacularDefinitionMap.get(language), language) ;
subject.addLiteral(DC.description,vernacularDefinitionLiteral) ; cropSubj.addLiteral(DC.description,vernacularDefinitionLiteral) ;
} }
else else
this._logger.warn("Empty vernacular crop description map for crop "+crop.getShortName()); 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) ; List<CropRule> rules = cropService.getCropRules(crop) ;
for(CropRule cr : rules) { for(CropRule cr : rules) {
String species = cr.getSpecies() ; String species = cr.getSpecies() ;
String genus = cr.getGenus() ; 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 { ...@@ -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 * @return
*/ */
private static String TitleCase(String s, Boolean capitalizeFirst) { public static String canonicalID(String identifier, Boolean capitalizeFirst) {
String[] words = s.split("\\s") ; String[] words = identifier.split("\\s") ;
s = "" ; identifier = "" ;
for(String word: words) { for(String word: words) {
if(!capitalizeFirst) { if(!capitalizeFirst) {
// only run once in the loop if false (reset to true...) // only run once in the loop if false (reset to true...)
s += word.toLowerCase() ; identifier += word.toLowerCase() ;
capitalizeFirst = true ; capitalizeFirst = true ;
} else { } else {
s += word.substring(0,1).toUpperCase() ; identifier += word.substring(0,1).toUpperCase() ;
s += word.substring(1).toLowerCase() ; identifier += word.substring(1).toLowerCase() ;
} }
} }
return s ; return identifier ;
} }
/* /*
...@@ -150,9 +153,9 @@ public abstract class RdfBaseController extends BaseController { ...@@ -150,9 +153,9 @@ public abstract class RdfBaseController extends BaseController {
subject.addProperty(RDF.type, SKOS.Concept) ; subject.addProperty(RDF.type, SKOS.Concept) ;
if(isProperty) if(isProperty)
tag= TitleCase(tag,false) ; tag= canonicalID(tag,false) ;
else else
tag = TitleCase(tag,true) ; tag = canonicalID(tag,true) ;
subject.addProperty(SKOS.hiddenLabel,tag) ; subject.addProperty(SKOS.hiddenLabel,tag) ;
// dc:creator <user> // 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