}
public void produceRDF()
{
Model model = ParserUtil.getModelProperties();
Resource root = model.createResource( baseURI + "dsd/" + fileName.substring(0,fileName.indexOf("_DSD")) );
model.add(root,ParserUtil.type,ParserUtil.dsd).add(root,ParserUtil.notation,fileName);
for(Dimension dim:lstDimensions)
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.property + (dim.getConceptRef().toLowerCase().equals("time_period") ? "time" : dim.getConceptRef().toLowerCase()));
model.add(component_1,ParserUtil.dimension,prop);
model.add(prop,ParserUtil.type,ParserUtil.dimensionProperty);
model.add(prop,ParserUtil.type,ParserUtil.codedProperty);
model.add(prop,ParserUtil.rdfsDomain,ParserUtil.observation);
if(!dim.getCodeList().equals(""))
{
for(CodeList obj:lstCodeLists)
{
if(obj.getId().toString().equals(dim.getCodeList().toString()))
{
if(obj.getAgencyID().equals("SDMX"))
{
// re-use the URI from sdmx-code.ttl file
String codeList = getCodeList(obj.getId());
Property cList = model.createProperty(ParserUtil.sdmx_code + codeList);
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.sdmx_concept + codeList);
model.add(prop,ParserUtil.concept,cncpt);
}
else
{
Property cList = model.createProperty(ParserUtil.dicURI + obj.getId().substring(obj.getId().indexOf("_")+1).toLowerCase());
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.concepts + (dim.getConceptRef().toLowerCase().equals("time_period") ? "time" : dim.getConceptRef().toLowerCase()));
model.add(prop,ParserUtil.concept,cncpt);
}
}
}
}
else
{
Property type = model.createProperty(ParserUtil.xsd + dim.getDataType().toLowerCase());
model.add(prop,ParserUtil.rdfsRange,type);
}
}
if(!obsValue.equals(""))
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.sdmx_measure + obsValue);
model.add(component_1,ParserUtil.dimension,prop);
}
if(!freq.equals(""))
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.sdmx_dimension + freq);
model.add(component_1,ParserUtil.dimension,prop);
}
if(!timePeriod.equals(""))
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.dcterms + "date");
model.add(component_1,ParserUtil.dimension,prop);
}
//
for(Dimension dim:lstTimeDimensions)
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.property + (dim.getConceptRef().toLowerCase().equals("time_period") ? "time" : dim.getConceptRef().toLowerCase()));
model.add(component_1,ParserUtil.dimension,prop);
model.add(prop,ParserUtil.type,ParserUtil.dimensionProperty);
model.add(prop,ParserUtil.rdfsDomain,ParserUtil.observation);
if(!dim.getCodeList().equals(""))
{
for(CodeList obj:lstCodeLists)
{
if(obj.getId().toString().equals(dim.getCodeList().toString()))
{
if(obj.getAgencyID().equals("SDMX"))
{
String codeList = getCodeList(obj.getId());
Property cList = model.createProperty(ParserUtil.sdmx_code + codeList);
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.sdmx_concept + codeList);
model.add(prop,ParserUtil.concept,cncpt);
}
else
{
Property cList = model.createProperty(ParserUtil.dicURI + obj.getId().substring(obj.getId().indexOf("_")+1).toLowerCase());
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.concepts + (dim.getConceptRef().toLowerCase().equals("time_period") ? "time" : dim.getConceptRef().toLowerCase()));
model.add(prop,ParserUtil.concept,cncpt);
}
}
}
}
else
{
Property type = model.createProperty(ParserUtil.xsd + dim.getDataType().toLowerCase());
model.add(prop,ParserUtil.rdfsRange,type);
}
}
//
for(Measure measure:lstMeasures)
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.property + (measure.getConceptRef().toLowerCase().equals("time_period") ? "time" : measure.getConceptRef().toLowerCase()));
model.add(component_1,ParserUtil.measure,prop);
model.add(prop,ParserUtil.type,ParserUtil.measureProperty);
model.add(prop,ParserUtil.type,ParserUtil.codedProperty);
model.add(prop,ParserUtil.rdfsDomain,ParserUtil.observation);
if(!measure.getCodeList().equals(""))
{
for(CodeList obj:lstCodeLists)
{
if(obj.getId().toString().equals(measure.getCodeList().toString()))
{
if(obj.getAgencyID().equals("SDMX"))
{
String codeList = getCodeList(obj.getId());
Property cList = model.createProperty(ParserUtil.sdmx_code + codeList);
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.sdmx_concept + codeList);
model.add(prop,ParserUtil.concept,cncpt);
}
else
{
Property cList = model.createProperty(ParserUtil.dicURI + obj.getId().substring(obj.getId().indexOf("_")+1).toLowerCase());
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.concepts + (measure.getConceptRef().toLowerCase().equals("time_period") ? "time" : measure.getConceptRef().toLowerCase()));
model.add(prop,ParserUtil.concept,cncpt);
}
}
}
}
else
{
Property type = model.createProperty(ParserUtil.xsd + measure.getDataType().toLowerCase());
model.add(prop,ParserUtil.rdfsRange,type);
}
}
//
for(Attribute att:lstAttributes)
{
Resource component_1 = model.createResource();
model.add(root,ParserUtil.component,component_1);
Property prop = model.createProperty(ParserUtil.property + (att.getConceptRef().toLowerCase().equals("time_period") ? "time" : att.getConceptRef().toLowerCase()));
model.add(component_1,ParserUtil.attribute,prop);
model.add(prop,ParserUtil.type,ParserUtil.attributeProperty);
model.add(prop,ParserUtil.type,ParserUtil.codedProperty);
model.add(prop,ParserUtil.rdfsDomain,ParserUtil.observation);
for(CodeList obj:lstCodeLists)
{
if(obj.getId().toString().equals(att.getCodeList().toString()))
{
if(obj.getAgencyID().equals("SDMX"))
{
// re-use the URI from sdmx-code.ttl file
String codeList = getCodeList(obj.getId());
Property cList = model.createProperty(ParserUtil.sdmx_code + codeList);
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.sdmx_concept + codeList);
model.add(prop,ParserUtil.concept,cncpt);
}
else
{
Property cList = model.createProperty(ParserUtil.dicURI + obj.getId().substring(obj.getId().indexOf("_")+1).toLowerCase());
model.add(prop,ParserUtil.codeList,cList);
model.add(prop,ParserUtil.rdfsRange,ParserUtil.skosConcept);
Property cncpt = model.createProperty(ParserUtil.concepts + (att.getConceptRef().toLowerCase().equals("time_period") ? "time" : att.getConceptRef().toLowerCase()));
model.add(prop,ParserUtil.concept,cncpt);
}
}
}
}
// translates code lists
String codeListID = "";
String name;
HashMap<String, String> hshName = new HashMap<String, String>();
for(CodeList obj:lstCodeLists)
{
if(!obj.getAgencyID().equals("SDMX"))
{
codeListID = obj.getId().substring(obj.getId().indexOf("_")+1);
Resource codeLists = model.createResource(baseURI + "dic/" + codeListID.toLowerCase());
model.add(codeLists,ParserUtil.type,ParserUtil.conceptScheme);
model.add(codeLists,ParserUtil.notation,obj.getId().toLowerCase());
// print multilingual labels
hshName = obj.gethshName();
Iterator entrySetIterator = hshName.entrySet().iterator();
while (entrySetIterator.hasNext())
{
Map.Entry entry = (Map.Entry) entrySetIterator.next();
String key = (String) entry.getKey();
name = hshName.get(key);
model.add(codeLists,ParserUtil.rdfsLabel,model.createLiteral(name,key));
}
ArrayList<Code> arrCode = obj.getCode();
for(Code code:arrCode)
{
String str = baseURI + "dic/" + codeListID.toLowerCase() + "#" + code.getValue();
Resource res = model.createResource(str);
model.add(codeLists,ParserUtil.topConcept,res);
model.add(res,ParserUtil.type,ParserUtil.skosConcept);
// print multilingual labels
hshName = code.gethshDescription();
Iterator entryIterator = hshName.entrySet().iterator();
while (entryIterator.hasNext())
{
Map.Entry entry = (Map.Entry) entryIterator.next();
String key = (String) entry.getKey();
name = hshName.get(key);
model.add(res,ParserUtil.skosLabel, model.createLiteral(name,key));
}
str = str.substring(0,str.indexOf("#"));
Resource resource = model.createResource(str);
model.add(res,ParserUtil.skosScheme,resource);
model.add(res,ParserUtil.notation,code.getValue());
}
}
}
for(Concept concept:lstConcepts)
{
Resource con = model.createResource(ParserUtil.concepts + (concept.getId().toLowerCase().equals("time_period") ? "time" : concept.getId().toLowerCase()));
model.add(con,ParserUtil.type,ParserUtil.sdmx);
model.add(con,ParserUtil.notation,concept.getId().toLowerCase().equals("time_period") ? "time" : concept.getId().toLowerCase());
//print multilingual labels
hshName = concept.gethshName();
Iterator entrySetIterator = hshName.entrySet().iterator();
while (entrySetIterator.hasNext())
{
Map.Entry entry = (Map.Entry) entrySetIterator.next();
String key = (String) entry.getKey();
name = hshName.get(key);
//writeLinetoFile(" skos:prefLabel \"" + name + "\"@" + key + ";");
model.add(con,ParserUtil.skosLabel,model.createLiteral(name,key));
}
Resource res = model.createResource(ParserUtil.concepts);
model.add(con,ParserUtil.skosScheme,res);
}
writeRDFToFile(fileName,model);