use of com.localidata.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateData method writeSkosTTL.
private 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 && !kosCreated.contains(dataBean.getNameNormalized()) && dataBean.getMapSkos().size() > 0) {
String suject = Prop.host + "/" + Prop.kosName + "/" + Prop.datasetName + "/" + dataBean.getKosName();
resultIni.append("<" + suject + "> " + "a skos:ConceptScheme;\n");
resultIni.append("\tskos:notation \"" + dataBean.getNameNormalized() + "\";\n");
resultIni.append("\trdfs:label \"" + dataBean.getName() + "\";\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 + ">;\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.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");
}
use of com.localidata.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateData method readMappingFile.
private HashMap<String, SkosBean> readMappingFile(String skosPath) {
log.debug("Init readSkosFile");
HashMap<String, SkosBean> mapSkos = new HashMap<String, SkosBean>();
File skosMappingg = new File(configDirectoryString + File.separator + skosPath);
InputStream inp = null;
Workbook wb = null;
try {
inp = new FileInputStream(skosMappingg);
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());
}
if (wb != null) {
Sheet sheet = wb.getSheetAt(0);
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
Row row = sheet.getRow(i);
Cell cellId = row.getCell(0);
Cell cellUri = row.getCell(1);
SkosBean skosBean = new SkosBean();
SkosBean skosBeanExtra = new SkosBean();
String idCell = "";
if (cellId.getCellType() == 0) {
Double d = new Double(cellId.getNumericCellValue());
idCell = d.intValue() + "";
} else {
idCell = cellId.getStringCellValue();
}
skosBean.setLabel(idCell);
idCell = Utils.urlify(idCell);
skosBean.setId(idCell);
String uriCell = "";
if (cellUri.getCellType() == 0) {
Double d = new Double(cellUri.getNumericCellValue());
uriCell = d.intValue() + "";
} else {
uriCell = cellUri.getStringCellValue();
String id = uriCell.substring(uriCell.lastIndexOf("/") + 1, uriCell.length());
if (!idCell.equals(id)) {
skosBeanExtra.setId(id);
skosBeanExtra.setLabel(id);
skosBeanExtra.setURI(uriCell);
mapSkos.put(id, skosBeanExtra);
}
}
skosBean.setURI(uriCell);
mapSkos.put(idCell, skosBean);
}
}
log.debug("End readSkosFile");
return mapSkos;
}
use of com.localidata.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateData method readConfig.
private void readConfig() {
log.debug("Init readConfig");
log.info("Comienza a extraerse la configuraciĆ³n");
File configDirectoryFile = new File(configDirectoryString);
File areasReportFile = new File(outputDirectoryString + File.separator + "areas.txt");
Collection<File> listCSV = FileUtils.listFiles(configDirectoryFile, extensionsConfig, true);
int cont = 0;
int size = listCSV.size();
for (File file : listCSV) {
log.info("Se extrae el fichero " + file.getName() + " " + (++cont) + " " + size);
if (!file.getName().startsWith("mapping")) {
ConfigBean configBean = new ConfigBean();
configBean.setNameFile(file.getName());
String id = file.getName().substring(8);
String areas = "";
id = id.replace(".csv", "");
id = id.replace(".xlsx", "");
if (id.contains("TC")) {
id = id.replace("TC", "");
configBean.getLetters().add("TC");
areas += "TC ";
}
if (id.contains("TM")) {
id = id.replace("TM", "");
configBean.getLetters().add("TM");
areas += "TM ";
}
if (id.contains("TP")) {
id = id.replace("TP", "");
configBean.getLetters().add("TP");
areas += "TP ";
}
if (id.contains("A")) {
id = id.replace("A", "");
configBean.getLetters().add("A");
areas += "A ";
}
while (id.charAt(id.length() - 1) == '-') {
id = id.substring(0, id.length() - 1);
}
configBean.setId(id);
if (Prop.formatConfig.equals("csv")) {
readCsv(file, configBean);
} else {
readXlsxFile(file, configBean);
}
mapconfig.put(id, configBean);
Utils.stringToFileAppend(id + " " + areas + "\n", areasReportFile);
}
}
for (Iterator<DataBean> it1 = dataWithSkosHierarchical.iterator(); it1.hasNext(); ) {
DataBean data1 = (DataBean) it1.next();
if (data1.getRelationKos() != null) {
DataBean data2 = mapconfig.get(data1.getIdConfig()).getMapData().get(data1.getRelationKos());
HashMap<String, SkosBean> mapSkos = data1.mergeSkos(data2);
if (mapSkos != null) {
log.info("Kos " + data1.getName() + " is parent of " + data2.getName());
data2.setWriteSkos(false);
data1.setMapSkos(mapSkos);
data2.setMapSkos(mapSkos);
mapconfig.get(data1.getIdConfig()).getMapData().get(data1.getNameNormalized()).setMapSkos(mapSkos);
mapconfig.get(data2.getIdConfig()).getMapData().get(data2.getNameNormalized()).setMapSkos(mapSkos);
}
}
}
log.info("Finaliza de extraerse la configuraciĆ³n");
log.debug("End readConfig");
}
use of com.localidata.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateData method readCsv.
private void readCsv(File file, ConfigBean configBean) {
log.debug("Init readCsv");
List<String> csvLines;
try {
csvLines = FileUtils.readLines(file, "UTF-8");
String[] cellsName = csvLines.get(0).split(",");
String[] cellsNameNormalized = csvLines.get(1).split(",");
String[] cellsNormalization = csvLines.get(2).split(",");
String[] cellsDimMesure = csvLines.get(3).split(",");
String[] cellsType = csvLines.get(4).split(",");
String[] cellsSkosfile = csvLines.get(5).split(",");
String[] cellsConstant = null;
String[] cellsConstantValue = null;
String[] cellsRelationKos = null;
String[] cellsKosName = null;
if (csvLines.size() == 7)
cellsConstant = csvLines.get(6).split(",");
if (csvLines.size() == 8)
cellsConstantValue = csvLines.get(7).split(",");
if (csvLines.size() == 9)
cellsRelationKos = csvLines.get(9).split(",");
if (csvLines.size() == 10)
cellsKosName = csvLines.get(10).split(",");
int columnReaded = 0;
while (columnReaded < cellsName.length) {
DataBean dataBean = new DataBean();
if (cellsName[columnReaded] == null) {
columnReaded++;
} else {
dataBean.setName(removeStartEndCaracter(cellsName[columnReaded]));
dataBean.setNameNormalized(removeStartEndCaracter(cellsNameNormalized[columnReaded]));
dataBean.setNormalizacion(removeStartEndCaracter(cellsNormalization[columnReaded]));
dataBean.setDimensionMesure(removeStartEndCaracter(cellsDimMesure[columnReaded]));
dataBean.setIdConfig(configBean.getId());
String type = "";
if (Utils.v(removeStartEndCaracter(cellsType[columnReaded]))) {
type = removeStartEndCaracter(cellsType[columnReaded]);
} else {
type = "xsd:string";
}
dataBean.setType(type);
if (Utils.v(removeStartEndCaracter(cellsSkosfile[columnReaded]))) {
HashMap<String, SkosBean> mapSkos = readMappingFileCSV(removeStartEndCaracter(cellsSkosfile[columnReaded]));
dataBean.setMapSkos(mapSkos);
configBean.getMapData().put(dataBean.getNameNormalized(), dataBean);
dataWithSkos.add(dataBean);
} else {
configBean.getMapData().put(dataBean.getNameNormalized(), dataBean);
}
if (Prop.addDataConstant && cellsConstant != null && Utils.v(removeStartEndCaracter(cellsConstant[columnReaded])) && removeStartEndCaracter(cellsConstant[columnReaded]).equals(Constants.constante)) {
if (Utils.v(removeStartEndCaracter(cellsConstantValue[columnReaded]))) {
dataBean.setConstant(removeStartEndCaracter(cellsConstantValue[columnReaded]) + "");
configBean.getListDataConstant().add(dataBean);
}
}
if (cellsRelationKos != null && Utils.v(removeStartEndCaracter(cellsRelationKos[columnReaded]))) {
dataBean.setRelationKos(removeStartEndCaracter(cellsRelationKos[columnReaded]));
dataWithSkosHierarchical.add(dataBean);
}
if (cellsKosName != null && Utils.v(removeStartEndCaracter(cellsKosName[columnReaded]))) {
dataBean.setKosName(removeStartEndCaracter(cellsKosName[columnReaded]));
} else {
dataBean.setKosName(dataBean.getNameNormalized());
}
columnReaded++;
}
}
} catch (IOException e) {
log.error("Error read csv ", e);
}
log.debug("End readCsv");
}
use of com.localidata.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateData 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 rowKosName = sheet.getRow(9);
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);
DataBean dataBean = new DataBean();
if (cellName == null) {
if (rowName.getCell((columnReaded + 1)) == null)
cont = false;
else
columnReaded++;
} else {
dataBean.setName(cellName.getStringCellValue());
dataBean.setNameNormalized(cellNameNormalized.getStringCellValue());
dataBean.setNormalizacion(cellNormalization.getStringCellValue());
dataBean.setDimensionMesure(cellDimMesure.getStringCellValue());
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) {
dataBean.setRelationKos(cellRelationKos.getStringCellValue());
dataWithSkosHierarchical.add(dataBean);
}
if (cellKosName != null) {
dataBean.setKosName(cellKosName.getStringCellValue());
} else {
dataBean.setKosName(dataBean.getNameNormalized());
}
columnReaded++;
}
}
log.debug("End readXlsxFile");
}
Aggregations