use of com.localidata.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateConfig method extractSkosConcept.
private void extractSkosConcept(List<String> csvLines, ArrayList<DataBean> skosData) {
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 {
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);
}
} 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.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateConfig method generateSkosMapping.
public void generateSkosMapping() {
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) {
GoogleDriveAPI api = new GoogleDriveAPI();
api.init();
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.process.bean.SkosBean in project local-data-aragopedia by aragonopendata.
the class GenerateData method readMappingFileCSV.
private HashMap<String, SkosBean> readMappingFileCSV(String skosPath) {
log.debug("Init readMappingFileCSV");
HashMap<String, SkosBean> mapSkos = new HashMap<String, SkosBean>();
if (skosPath.endsWith("xlsx"))
skosPath = skosPath.replace("xlsx", "csv");
File skosMappingg = new File(configDirectoryString + File.separator + skosPath);
List<String> csvLines;
try {
csvLines = FileUtils.readLines(skosMappingg, "UTF-8");
for (String line : csvLines) {
String[] cells = line.split("\",\"");
String cellId = removeStartEndCaracter(cells[0]);
String cellUri = removeStartEndCaracter(cells[1]);
SkosBean skosBean = new SkosBean();
SkosBean skosBeanExtra = new SkosBean();
skosBean.setLabel(cellId);
cellId = Utils.urlify(cellId);
skosBean.setId(cellId);
String id = cellUri.substring(cellUri.lastIndexOf("/") + 1, cellUri.length());
if (!cellId.equals(id)) {
skosBeanExtra.setId(id);
skosBeanExtra.setLabel(id);
skosBeanExtra.setURI(cellUri);
mapSkos.put(id, skosBeanExtra);
}
skosBean.setURI(cellUri);
mapSkos.put(cellId, skosBean);
}
} catch (IOException e) {
log.error("Error read csv ", e);
}
log.debug("End readMappingFileCSV");
return mapSkos;
}
Aggregations