use of com.localidata.bean.DataBean in project local-data-aragopedia by aragonopendata.
the class GenerateConfig method generateSkosMapping.
public void generateSkosMapping(boolean update) {
log.debug("Init generateSkosMapping");
String filedSeparator = "\"";
String csvSeparator = ",";
for (String key : GenerateConfig.skosExtrated.keySet()) {
StringBuffer content = new StringBuffer();
DataBean data = GenerateConfig.skosExtrated.get(key);
for (String skosName : data.getMapSkos().keySet()) {
SkosBean skosBean = data.getMapSkos().get(skosName);
if (Utils.v(skosBean.getId()))
content.append(filedSeparator + skosBean.getLabel() + filedSeparator + csvSeparator + filedSeparator + skosBean.getURI() + filedSeparator + System.getProperty("line.separator"));
}
String nameFile = "mapping-" + Utils.urlify(data.getName());
String pathFile = configDirectoryString + File.separator + nameFile + ".csv";
log.info("comienza a escribirse el archivo " + nameFile + ".csv");
File file = new File(pathFile);
try {
Utils.stringToFile(content.toString(), file);
if (Prop.publishDrive) {
if (!update) {
GoogleDriveAPI api = new GoogleDriveAPI();
api.init();
com.google.api.services.drive.model.File f = api.searchFile(nameFile);
if (f == null)
api.createSpreadsheetFromFile(Prop.idParentFolder, Prop.emailUserFile, "csv", nameFile, file, "text/csv");
}
}
log.info("finaliza de escribirse el archivo " + nameFile + ".csv");
} catch (Exception e) {
log.error("Error to generate skos mapping " + pathFile, e);
}
}
log.debug("End generateSkosMapping");
}
use of com.localidata.bean.DataBean in project local-data-aragopedia by aragonopendata.
the class GenerateConfig method extractSkosConcept.
private void extractSkosConcept(List<String> csvLines, ArrayList<DataBean> skosData, ConfigBean configBean) {
log.debug("Init extractSkosConcept");
String headerLine = Utils.weakClean(csvLines.get(0));
String[] cells = headerLine.split("\t");
int[] posColumn = new int[skosData.size()];
for (int h = 0; h < skosData.size(); h++) {
String name = skosData.get(h).getName();
for (int i = 0; i < cells.length; i++) {
if (cells[i].equalsIgnoreCase(name)) {
boolean incluido = false;
for (int j = 0; j < posColumn.length; j++) {
if (posColumn[j] == i)
incluido = true;
}
if (!incluido) {
posColumn[h] = i;
break;
}
}
}
}
for (int h = 1; h < csvLines.size(); h++) {
String line = Utils.weakClean(csvLines.get(h));
if (Utils.v(line)) {
cells = line.split("\t");
for (int i = 0; i < skosData.size(); i++) {
try {
if (cells.length > posColumn[i]) {
String cell = cells[posColumn[i]];
SkosBean skosBean = new SkosBean();
String skosUrified = Utils.urlify(cell);
skosBean.setId(skosUrified);
skosBean.setLabel(Utils.weakClean(cell));
skosBean.setURI(Prop.host + "/kos/" + Prop.datasetName + "/" + Utils.urlify(skosData.get(i).getName()) + "/" + skosUrified);
DataBean dataBean = null;
if (skosExtrated.get(skosData.get(i).getName()) != null) {
dataBean = skosExtrated.get(skosData.get(i).getName());
} else {
dataBean = skosData.get(i);
}
if (dataBean.getMapSkos().get(skosBean.getId()) == null) {
dataBean.getMapSkos().put(skosBean.getId(), skosBean);
skosExtrated.put(dataBean.getName(), dataBean);
if (configBean != null)
configBean.getMapData().put(dataBean.getName(), dataBean);
}
}
} catch (ArrayIndexOutOfBoundsException e) {
log.error("ERROR al extraer los skos debido a incoherencia de columnas", e);
DataBean dataBean = null;
if (skosExtrated.get(skosData.get(i).getName()) != null) {
dataBean = skosExtrated.get(skosData.get(i).getName());
} else {
dataBean = skosData.get(i);
}
skosExtrated.put(dataBean.getName(), dataBean);
}
}
}
}
log.debug("End extractSkosConcept");
}
use of com.localidata.bean.DataBean in project local-data-aragopedia by aragonopendata.
the class GenerateRDF method readXlsxFile.
private void readXlsxFile(File file, ConfigBean configBean) {
log.debug("Init readXlsxFile");
InputStream inp = null;
Workbook wb = null;
try {
inp = new FileInputStream(file);
wb = WorkbookFactory.create(inp);
} catch (FileNotFoundException e) {
log.error(e.getMessage());
} catch (InvalidFormatException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
Sheet sheet = wb.getSheetAt(0);
Row rowName = sheet.getRow(0);
Row rowNameNormalized = sheet.getRow(1);
Row rowNormalization = sheet.getRow(2);
Row rowDimMesure = sheet.getRow(3);
Row rowType = sheet.getRow(4);
Row rowSkosfile = sheet.getRow(5);
Row rowConstant = sheet.getRow(6);
Row rowConstantValue = sheet.getRow(7);
Row rowRelationKos = sheet.getRow(8);
Row rowKosNameNormalized = sheet.getRow(9);
Row rowKosName = sheet.getRow(10);
boolean cont = true;
int columnReaded = 0;
while (cont) {
Cell cellName = rowName.getCell(columnReaded);
Cell cellNameNormalized = rowNameNormalized.getCell(columnReaded);
Cell cellNormalization = rowNormalization.getCell(columnReaded);
Cell cellDimMesure = rowDimMesure.getCell(columnReaded);
Cell cellType = rowType.getCell(columnReaded);
Cell cellSkosfile = null;
if (rowSkosfile != null)
cellSkosfile = rowSkosfile.getCell(columnReaded);
Cell cellConstant = null;
if (rowConstant != null)
cellConstant = rowConstant.getCell(columnReaded);
Cell cellConstantValue = null;
if (rowConstantValue != null)
cellConstantValue = rowConstantValue.getCell(columnReaded);
Cell cellRelationKos = null;
if (rowRelationKos != null)
cellRelationKos = rowRelationKos.getCell(columnReaded);
Cell cellKosName = null;
if (rowKosName != null)
cellKosName = rowKosName.getCell(columnReaded);
Cell cellKosNameNormalized = null;
if (rowKosNameNormalized != null)
cellKosNameNormalized = rowKosNameNormalized.getCell(columnReaded);
DataBean dataBean = new DataBean();
if (cellName == null) {
if (rowName.getCell((columnReaded + 1)) == null)
cont = false;
else
columnReaded++;
} else {
dataBean.setName(cellName.getStringCellValue());
if (cellNameNormalized != null) {
dataBean.setNameNormalized(cellNameNormalized.getStringCellValue());
} else {
log.error("Error in config " + file.getName() + " in cell name normalized");
}
if (cellNormalization != null) {
dataBean.setNormalizacion(cellNormalization.getStringCellValue());
} else {
log.error("Error in config " + file.getName() + " in cell normalization");
}
if (cellDimMesure != null) {
dataBean.setDimensionMesure(cellDimMesure.getStringCellValue());
} else {
log.error("Error in config " + file.getName() + " in cell dim mesure");
}
dataBean.setIdConfig(configBean.getId());
String type = "";
if (cellType != null) {
type = cellType.getStringCellValue();
} else {
type = "xsd:string";
}
dataBean.setType(type);
if (cellSkosfile != null && !cellSkosfile.getStringCellValue().equals("")) {
HashMap<String, SkosBean> mapSkos = readMappingFile(cellSkosfile.getStringCellValue());
dataBean.setMapSkos(mapSkos);
configBean.getMapData().put(dataBean.getNameNormalized(), dataBean);
dataWithSkos.add(dataBean);
} else {
configBean.getMapData().put(dataBean.getNameNormalized(), dataBean);
}
if (Prop.addDataConstant && cellConstant != null && cellConstant.getStringCellValue().equals(Constants.constante)) {
if (cellConstantValue != null) {
dataBean.setConstant(cellConstantValue.getStringCellValue() + "");
configBean.getListDataConstant().add(dataBean);
}
}
if (cellRelationKos != null) {
if (Utils.v(cellRelationKos.getStringCellValue())) {
dataBean.setRelationKos(cellRelationKos.getStringCellValue());
dataWithSkosHierarchical.add(dataBean);
}
}
if (Utils.v(cellKosNameNormalized) && Utils.v(cellKosNameNormalized.getStringCellValue())) {
dataBean.setKosNameNormalized(cellKosNameNormalized.getStringCellValue());
} else {
dataBean.setKosNameNormalized(dataBean.getNameNormalized());
}
if (Utils.v(cellKosName) && Utils.v(cellKosName.getStringCellValue())) {
dataBean.setKosName(cellKosName.getStringCellValue());
} else {
dataBean.setKosName(dataBean.getName());
}
columnReaded++;
}
}
log.debug("End readXlsxFile");
}
use of com.localidata.bean.DataBean in project local-data-aragopedia by aragonopendata.
the class TransformToRDF method generateCommonData.
public void generateCommonData(HashMap<String, ConfigBean> mapconfig, HashMap<String, String> idDescription) {
int numfile = 1;
File specsTtlFile = new File(specsTtlFileString);
try {
List<String> specsLines = FileUtils.readLines(specsTtlFile, "UTF-8");
for (String line : specsLines) {
if (line.contains(" api:label ")) {
String[] column = line.split(" ");
viewsSpecsTtl.add(column[0]);
}
}
} catch (Exception e) {
log.error("Error generando los datos comunes (dsd, properties, kos)", e);
}
for (String keyConfig : mapconfig.keySet()) {
ConfigBean config = mapconfig.get(keyConfig);
boolean year = false;
String resultado = "";
String aux = "";
resultado = Prop.host + "/" + Prop.eldaName + "/" + Prop.datasetName + "/dsd/" + config.getId();
aux = "<" + resultado + "> a qb:DataStructureDefinition ;" + "\n";
String description = "";
if (config != null && config.getId() != null && config.getLetters() != null && config.getLetters().size() > 0)
description = idDescription.get(config.getId() + config.getLetters().get(0)) != null ? idDescription.get(config.getId() + config.getLetters().get(0)) : "";
aux = aux + "\trdfs:label \"Estructura de los cubos de datos que se corresponden con los informes " + config.getId() + ", " + description + "\"@es ;" + "\n";
String notation = "\"DSD-" + config.getId() + "\"";
aux = aux + "\tskos:notation " + notation + " ;" + "\n";
String letters = "";
for (String letter : config.getLetters()) {
letters += letter + " ";
}
aux = aux + "\trdfs:comment \"Esta estructura afecta a las areas: " + letters + "\"^^xsd:string ." + "\n";
aux = aux + "\n";
insertDsd(aux, resultado + " " + notation);
int col = 1;
for (String keyData : config.getMapData().keySet()) {
DataBean data = config.getMapData().get(keyData);
boolean noRepetido = true;
if (Utils.v(data.getNormalizacion())) {
if (!propertiesList.contains(data.getNormalizacion())) {
propertiesList.add(data.getNormalizacion());
if (!viewsSpecsTtl.contains(data.getNormalizacion())) {
insertViewTTL(data.getNormalizacion());
}
} else {
noRepetido = false;
}
if (!data.getNormalizacion().contains("sdmx-dimension:refPeriod")) {
aux = "<" + resultado + "> qb:component _:node" + numfile + "egmfx" + col + " ." + "\n";
if (!dsdList.contains(resultado + " " + data.getDimensionMesure() + " " + data.getNormalizacion())) {
Utils.stringToFileAppend(aux, dsdFile);
}
if (!data.getType().contains(Constants.URIType)) {
aux = "_:node" + numfile + "egmfx" + col + " " + data.getDimensionMesure() + " " + data.getNormalizacion() + " ." + "\n";
aux = aux + "\n";
insertDsd(aux, resultado + " " + data.getDimensionMesure() + " " + data.getNormalizacion());
if (noRepetido && data.isWriteSkos()) {
String coded = data.getDimensionMesure().equals(Constants.mesure) ? "" : ", qb:CodedProperty ";
propertiesContent.append(data.getNormalizacion() + " a " + data.getDimensionMesureProperty() + " , rdf:Property" + coded + ";" + "\n");
propertiesContent.append("\trdfs:label \"" + Utils.weakClean(data.getKosName()) + "\"@es ;" + "\n");
propertiesContent.append("\trdfs:comment \"" + Utils.weakClean(data.getKosName()) + "\"@es ;" + "\n");
propertiesContent.append("\trdfs:range " + data.getType());
if (data.getType().equals(Constants.skosType)) {
if (data.getMapSkos().keySet().size() > 0) {
String key = data.getMapSkos().keySet().iterator().next();
if (Utils.v(key)) {
String codeList = data.getMapSkos().get(key).getURI();
if (Utils.v(codeList)) {
propertiesContent.append(" ;" + "\n");
codeList = codeList.substring(0, codeList.lastIndexOf("/"));
propertiesContent.append("\tqb:codeList <" + codeList + "> ." + "\n");
} else {
propertiesContent.append(".\n");
}
} else {
propertiesContent.append(".\n");
}
} else {
propertiesContent.append(" ." + "\n");
if (Utils.weakClean(data.getName()).equals("")) {
TransformToRDF.insertError(config.getId() + ". ERROR. CELL EMPTY " + ". SKOS FOR THIS COLUMN NOT FOUND ");
log.error(config.getId() + ". ERROR. CELL EMPTY " + ". SKOS FOR THIS COLUMN NOT FOUND ");
}
TransformToRDF.insertError(config.getId() + ". ERROR. Column " + Utils.weakClean(data.getName()) + ". SKOS FOR THIS COLUMN NOT FOUND ");
log.error(config.getId() + ". ERROR. Column " + Utils.weakClean(data.getName()) + ". SKOS FOR THIS COLUMN NOT FOUND ");
}
} else {
propertiesContent.append(" ." + "\n");
}
propertiesContent.append("" + "\n");
Utils.stringToFileAppend(propertiesContent.toString(), propertiesFile);
propertiesContent.setLength(0);
}
} else {
aux = "_:node" + numfile + "egmfx" + col + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refArea ." + "\n";
aux = aux + "\n";
insertDsd(aux, resultado + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refArea");
}
} else {
year = true;
aux = "<" + resultado + "> qb:component _:node" + numfile + "egmfx" + col + " ." + "\n";
aux = aux + "_:node" + numfile + "egmfx" + col + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refPeriod ." + "\n";
aux = aux + "\n";
insertDsd(aux, resultado + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refPeriod");
}
col++;
}
}
if (!year) {
aux = "<" + resultado + "> qb:component _:node" + numfile + "egmfx" + col + " ." + "\n";
aux = aux + "_:node" + numfile + "egmfx" + col + " qb:dimension sdmx-dimension:refPeriod ." + "\n";
aux = aux + "\n";
insertDsd(aux, resultado + " qb:dimension sdmx-dimension:refPeriod");
}
numfile++;
}
}
use of com.localidata.bean.DataBean in project local-data-aragopedia by aragonopendata.
the class GenerateRDF method writeSkosTTL.
public void writeSkosTTL() {
log.debug("Init createSkos");
log.info("Init to create skos");
File kosFile = new File(outputDirectoryString + File.separator + "DatosTTL" + File.separator + "codelists" + File.separator + "kos.ttl");
StringBuffer resultIni = new StringBuffer();
StringBuffer resultFin = new StringBuffer();
ArrayList<String> kosCreated = new ArrayList<String>();
resultIni.append(TransformToRDF.addPrefix());
for (Iterator<DataBean> itDataBean = dataWithSkos.iterator(); itDataBean.hasNext(); ) {
DataBean dataBean = itDataBean.next();
if (dataBean != null && dataBean.isWriteSkos() && !kosCreated.contains(dataBean.getNameNormalized()) && dataBean.getMapSkos().size() > 0) {
String suject = Prop.host + "/" + Prop.kosName + "/" + Prop.datasetName + "/" + dataBean.getKosNameNormalized();
resultIni.append("<" + suject + "> " + "a skos:ConceptScheme;\n");
resultIni.append("\tskos:notation \"" + dataBean.getKosNameNormalized() + "\";\n");
resultIni.append("\trdfs:label \"" + dataBean.getKosName() + "\";\n");
for (Iterator<String> iterator3 = dataBean.getMapSkos().keySet().iterator(); iterator3.hasNext(); ) {
String keySkos = iterator3.next();
SkosBean skosBean = dataBean.getMapSkos().get(keySkos);
if (skosBean != null) {
String sujectKos = suject + "/" + Utils.urlify(skosBean.getId());
if (skosBean.getParent() == null) {
resultIni.append("\tskos:hasTopConcept <" + sujectKos + ">");
if (iterator3.hasNext()) {
resultIni.append(";\n");
} else {
resultIni.append(".\n");
}
}
resultFin.append("<" + sujectKos + "> a skos:Concept;\n");
resultFin.append("\tskos:inScheme <" + suject + ">;\n");
String label = skosBean.getId();
if (skosBean.getLabel() != null && !skosBean.getLabel().equals(""))
label = skosBean.getLabel();
resultFin.append("\tskos:notation \"" + skosBean.getId() + "\";\n");
resultFin.append("\tskos:prefLabel \"" + Utils.prefLabelClean(label) + "\"");
if (skosBean.getParent() != null) {
resultFin.append(";\n");
resultFin.append("\tskos:broader <" + suject + "/" + skosBean.getParent().getId() + ">");
}
if (skosBean.getSons().size() > 0) {
resultFin.append(";\n");
for (Iterator<SkosBean> itSons = skosBean.getSons().iterator(); itSons.hasNext(); ) {
SkosBean son = itSons.next();
resultFin.append("\tskos:narrower <" + suject + "/" + son.getId() + ">");
if (itSons.hasNext()) {
resultFin.append(";\n");
} else {
resultFin.append(".\n");
}
}
} else {
resultFin.append(".\n");
}
resultFin.append("\n");
}
}
resultIni.append("\n");
resultIni.append(resultFin);
kosCreated.add(dataBean.getNameNormalized());
}
Utils.stringToFileAppend(resultIni.toString(), kosFile);
resultIni.setLength(0);
resultFin.setLength(0);
}
log.info("end to create skos");
log.debug("End createSkos");
}
Aggregations