Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trim strings when read csv file with subdivisions data #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
mkdir scripts/target/csv
cp locodes/*.csv scripts/target/csv

cp scripts/target/classes/**/*SubdivisionCodes.csv scripts/target/csv
- name: generate
working-directory: scripts/target/
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,6 @@
import java.util.*;

public class UNLOCODEToFilesByCode extends Transformer {

protected static String FUNCTION_CLASS_NAME = "Function";
protected static String FUNCTION_CLASS = StringUtils.join(UNLOCODE_VOCAB_NS, ":", FUNCTION_CLASS_NAME);
public static final String FUNCTIONS_PROPERTY_NAME = "functions";
public static String FUNCTIONS_PROPERTY = StringUtils.join(UNLOCODE_VOCAB_NS, ":", FUNCTIONS_PROPERTY_NAME);
public static String SUBDIVISION_CLASS_NAME = "Subdivision";
public static String SUBDIVISION_CLASS = StringUtils.join(UNLOCODE_VOCAB_NS, ":", SUBDIVISION_CLASS_NAME);
public static final String COUNTRY_SUBDIVISION_PROPERTY_NAME = "countrySubdivision";
public static String COUNTRY_SUBDIVISION_PROPERTY = StringUtils.join(UNLOCODE_VOCAB_NS, ":", COUNTRY_SUBDIVISION_PROPERTY_NAME);
public final static String SUBDIVISION_TYPE_PROPERTY_NAME = "subdivisionType";
public static String SUBDIVISION_TYPE_PROPERTY = StringUtils.join(UNLOCODE_VOCAB_NS, ":", SUBDIVISION_TYPE_PROPERTY_NAME);
public static String COUNTRY_CLASS_NAME = "Country";
public static String COUNTRY_CLASS = StringUtils.join(UNLOCODE_VOCAB_NS, ":", COUNTRY_CLASS_NAME);
public static String UNLOCODE_CLASS_NAME = "UNLOCODE";
public static String UNLOCODE_CLASS = StringUtils.join(UNLOCODE_VOCAB_NS, ":", UNLOCODE_CLASS_NAME);
public final static String PROPERTY_COUNTRY_CODE_NAME = "countryCode";
public static String PROPERTY_COUNTRY_CODE = StringUtils.join(UNLOCODE_VOCAB_NS, ":", PROPERTY_COUNTRY_CODE_NAME);


Map<String, JsonObject> countriesGraph = new TreeMap<>();
Map<String, JsonObject> subdivisionsGraph = new TreeMap<>();
Map<String, JsonObject> vocabGraph = new TreeMap<>();
Map<String, JsonObject> functionsGraph = new TreeMap<>();
Map<String, JsonObject> locodesGraph = new TreeMap<>();



public UNLOCODEToFilesByCode(Set<String> inputFiles, Set<String> defaultInputFiles, boolean prettyPrint) {
super(null);
setInputFiles(inputFiles);
Expand All @@ -60,7 +33,7 @@ protected JsonObjectBuilder getContext() {
}


public void transform() throws IOException, InvalidFormatException {
public void transform() throws IOException {
Map<String, Set<CSVRecord>> locodesByCountries = new TreeMap<>();
if (inputFiles.isEmpty()){
for (String file : defaultInputFiles) {
Expand All @@ -87,7 +60,6 @@ public void transform() throws IOException, InvalidFormatException {
else {
for (String file : inputFiles) {
BufferedReader reader = Files.newBufferedReader(Paths.get(file), Charset.forName("ISO-8859-1"));
String line = reader.readLine();
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT);
List<CSVRecord> records = csvParser.getRecords();
if (records.get(0).size() > 4) {
Expand All @@ -109,7 +81,6 @@ public void transform() throws IOException, InvalidFormatException {

for (String country:locodesByCountries.keySet()){
Set<CSVRecord> records = locodesByCountries.get(country);
Set<String> lines = new TreeSet<>();
Map<String, String> sortedLines = new HashMap<>();
Iterator<CSVRecord> iterator = records.iterator();
while (iterator.hasNext()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ public void transform() throws IOException, InvalidFormatException {
private void processSubdivisionCodes(List<CSVRecord> records) {
for (int i = 0; i < records.size(); i++) {
SubDivisionCode code = new SubDivisionCode(
records.get(i).get(0),
records.get(i).get(1),
records.get(i).get(2),
records.get(i).get(3)
records.get(i).get(0).trim(),
records.get(i).get(1).trim(),
records.get(i).get(2).trim(),
records.get(i).get(3).trim()
);
String id = StringUtils.join(code.getCountry(), code.getCode());
JsonObjectBuilder rdfClass = Json.createObjectBuilder();
Expand Down
Loading