Skip to content

Commit

Permalink
[Feature #15] Fix normalize propertyUris and column names
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Sep 17, 2021
1 parent e01d2f0 commit 5f42e64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected static Property property(String local )
public static final Property aboutUrl = property("aboutUrl");
public static final Property propertyUrl = property("propertyUrl");
public static final Property name = property("name");
public static final Property title = property("title");
public static final Property valueUrl = property("valueUrl");
public static final Property tableSchema = property("tableSchema");
public static final Property column = property("column");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ ExecutionContext executeSelf() {

String[] header = listReader.getHeader(true); // skip the header (can't be used with CsvListReader)


for (String columnName : header) {
Resource columnResource = ResourceFactory.createResource();
// TODO make sure normalized names does not clash
String columnNameNormalized = normalize(columnName);

outputModel.add(
T_Schema,
Expand All @@ -114,12 +117,17 @@ ExecutionContext executeSelf() {
outputModel.add(
columnResource,
CSVW.name,
ResourceFactory.createStringLiteral(columnName)
ResourceFactory.createStringLiteral(columnNameNormalized)
);
outputModel.add(
columnResource,
CSVW.title,
ResourceFactory.createStringLiteral(columnName)
);
outputModel.add(
columnResource,
CSVW.aboutUrl,
outputModel.createTypedLiteral(sourceResource.getUri() + "/columns/" + columnName + "-{_row}", CSVW.uriTemplate)
outputModel.createTypedLiteral(sourceResource.getUri() + "/columns/" + columnNameNormalized + "-{_row}", CSVW.uriTemplate)
);
}

Expand Down Expand Up @@ -195,16 +203,17 @@ ExecutionContext executeSelf() {
// 4.6.8.3
String propertyUrl = null; //TODO get from user
String columnName = header[i];
String normalizedColumnName = normalize(columnName);

Property P;
if (propertyUrl != null && !propertyUrl.isEmpty()) {
P = ResourceFactory.createProperty(propertyUrl);
} else if (dataPrefix != null && !dataPrefix.isEmpty()) {
P = ResourceFactory.createProperty(
dataPrefix + URLEncoder.encode(columnName, "UTF-8"));
dataPrefix + URLEncoder.encode(normalizedColumnName, "UTF-8"));
} else {
P = ResourceFactory.createProperty(
sourceResource.getUri() + "#" + URLEncoder.encode(columnName, "UTF-8")); //TODO should be URL (according to specification) not URI
sourceResource.getUri() + "#" + URLEncoder.encode(normalizedColumnName, "UTF-8")); //TODO should be URL (according to specification) not URI
}

String valueUrl = null; //TODO get from user
Expand Down Expand Up @@ -343,6 +352,10 @@ private void onTable(String tableUri) {
}
}

private String normalize(String label) {
return label.replaceAll("[^\\w]", "_");
}

private Reader getReader() {
return new StringReader(new String(sourceResource.getContent()));
}
Expand Down

0 comments on commit 5f42e64

Please sign in to comment.