From 09f93fed0e8567f4b470ced827ccf7eb9e5588c3 Mon Sep 17 00:00:00 2001 From: luccioman Date: Wed, 14 Feb 2018 10:31:09 +0100 Subject: [PATCH] Added a line start field for vocabulary import from CSV file As a convenience to ignore eventual CSV header lines --- htroot/Vocabulary_p.html | 10 ++++++---- htroot/Vocabulary_p.java | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/htroot/Vocabulary_p.html b/htroot/Vocabulary_p.html index 92ff93cb4..4779c724e 100644 --- a/htroot/Vocabulary_p.html +++ b/htroot/Vocabulary_p.html @@ -125,25 +125,27 @@ To see a list of all APIs, please visit the
-
Import from a csv file 
+
Import from a csv file 
File Path
+
Start line
+
(first has index 0)
Column for Literals
(first has index 0)
Synonyms
no Synonyms
Auto-Enrich with Synonyms from Stemming Library
Read Column
- (first has index 0) + (first has index 0)
Column for Object Link (optional)
(first has index 0, if unused set -1)
Charset of Import File
-
+
Column separator
-
diff --git a/htroot/Vocabulary_p.java b/htroot/Vocabulary_p.java index ffefbbb30..c8ba6356e 100644 --- a/htroot/Vocabulary_p.java +++ b/htroot/Vocabulary_p.java @@ -87,6 +87,7 @@ public class Vocabulary_p { final String discoverFromCSVPath = post.get("discoverpath", "").replaceAll("%20", " "); String discoverFromCSVCharset = post.get("charset", StandardCharsets.UTF_8.name()); final String columnSeparator = post.get("columnSeparator", ";"); + final int lineStart = post.getInt("discoverLineStart", 0); final int discovercolumnliteral = post.getInt("discovercolumnliteral", 0); final int discovercolumnsynonyms = post.getInt("discovercolumnsynonyms", -1); final int discovercolumnobjectlink = post.getInt("discovercolumnobjectlink", -1); @@ -108,12 +109,21 @@ public class Vocabulary_p { String line = null; final Pattern separatorPattern = Pattern.compile(columnSeparator); Map synonym2literal = new HashMap<>(); // helper map to check if there are double synonyms + int lineIndex = -1; while ((line = r.readLine()) != null) { - if (line.length() == 0) continue; + lineIndex++; + if(lineIndex < lineStart) { + continue; + } + if (line.length() == 0) { + continue; + } String[] l = separatorPattern.split(line); if (l.length == 0) l = new String[]{line}; String literal = discovercolumnliteral < 0 || l.length <= discovercolumnliteral ? null : l[discovercolumnliteral].trim(); - if (literal == null) continue; + if (literal == null) { + continue; + } literal = normalizeLiteral(literal); String objectlink = discovercolumnobjectlink < 0 || l.length <= discovercolumnobjectlink ? null : l[discovercolumnobjectlink].trim(); if (literal.length() > 0) {