Skip to content

Commit

Permalink
[Fix] Fixed usage of uriTemplate and column urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Zdenek committed Sep 30, 2021
1 parent 4b9e1f3 commit 0a896d6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,28 @@ ExecutionContext executeSelf() {
outputModel.add(
columnResource,
CSVW.aboutUrl,
outputModel.createTypedLiteral(sourceResource.getUri() + "/columns/" + columnName + "-{_row}", CSVW.uriTemplate)
outputModel.createTypedLiteral(sourceResource.getUri() + "#row-{_row}", CSVW.uriTemplate)
);
}

String columnPropertyUrl = null; //TODO get from inputModel
if (columnPropertyUrl != null && !columnPropertyUrl.isEmpty()) {
outputModel.add(
columnResource,
CSVW.propertyUrl,
outputModel.createTypedLiteral(columnPropertyUrl, CSVW.uriTemplate)
);
} else if (dataPrefix != null && !dataPrefix.isEmpty()) {
outputModel.add(
columnResource,
CSVW.propertyUrl,
ResourceFactory.createPlainLiteral(dataPrefix + URLEncoder.encode(columnName, "UTF-8")) //TODO should be URL (according to specification) not URI
);
} else {
outputModel.add(
columnResource,
CSVW.propertyUrl,
ResourceFactory.createPlainLiteral(sourceResource.getUri() + "#" + URLEncoder.encode(columnName, "UTF-8"))
);
}
}
Expand Down Expand Up @@ -194,7 +215,7 @@ ExecutionContext executeSelf() {
ResourceFactory.createTypedLiteral(Integer.toString(rowNumber),
XSDDatatype.XSDinteger));
// 4.6.5
final String rowIri = sourceResource.getUri() + "#row=" + listReader.getRowNumber(); // TODO check with specification
final String rowIri = sourceResource.getUri() + "#row=" + listReader.getRowNumber();
outputModel.add(
R,
CSVW.url,
Expand All @@ -212,22 +233,15 @@ ExecutionContext executeSelf() {
R = null;
}

// 4.6.8
//Resource S_def = ResourceFactory.createResource();

for (int i = 0; i < header.length; i++) {
// 4.6.8.1
String aboutUrl = null; //TODO get from inputModel
Resource schemaColumnResource = columns.get(i).asResource();

Resource S;
if (aboutUrl != null && !aboutUrl.isEmpty()) {
S = ResourceFactory.createResource(aboutUrl);
} else {
String columnAboutUrl = getAboutUrlFromSchema(columns.get(i).asResource());
S = ResourceFactory.createResource(columnAboutUrl.replace(
"{_row}",
Integer.toString(listReader.getRowNumber())));
}
// 4.6.8.1
String columnAboutUrl = getAboutUrlFromSchema(schemaColumnResource);
Resource S = ResourceFactory.createResource(columnAboutUrl.replace(
"{_row}",
Integer.toString(listReader.getRowNumber())
));

// 4.6.8.2
if (R != null) {
Expand All @@ -238,20 +252,8 @@ ExecutionContext executeSelf() {
}

// 4.6.8.3
String propertyUrl = null; //TODO get from inputModel
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(normalizedColumnName, "UTF-8"));
} else {
P = ResourceFactory.createProperty(
sourceResource.getUri() + "#" + URLEncoder.encode(normalizedColumnName, "UTF-8")); //TODO should be URL (according to specification) not URI
}
String columnPropertyUrl = getPropertyUrlFromSchema(schemaColumnResource);
Property P = ResourceFactory.createProperty(columnPropertyUrl);

String valueUrl = null; //TODO get from inputModel

Expand All @@ -262,6 +264,12 @@ ExecutionContext executeSelf() {
S,
P,
V_url));

outputModel.add(
schemaColumnResource,
CSVW.valueUrl,
ResourceFactory.createPlainLiteral(valueUrl)
);
} else {
final String cellValue = row.get(i);
if (cellValue != null) {
Expand Down Expand Up @@ -385,11 +393,6 @@ private void onTable(String tableUri) {
RDF.type,
CSVW.TableSchema
);
outputModel.add(
T_Schema,
CSVW.aboutUrl,
outputModel.createTypedLiteral(sourceResource.getUri() + "#table-{_table}", CSVW.uriTemplate) //TODO what should aboutUrl on table look like
);
}
}

Expand All @@ -406,7 +409,11 @@ private Resource getColumnByName(String columnName) {
}

private String getAboutUrlFromSchema(Resource columnResource) {
return outputModel.getRequiredProperty(columnResource, CSVW.aboutUrl).getObject().asLiteral().toString();
return outputModel.getRequiredProperty(columnResource, CSVW.aboutUrl).getObject().asLiteral().getString();
}

private String getPropertyUrlFromSchema(Resource columnResource) {
return outputModel.getRequiredProperty(columnResource, CSVW.propertyUrl).getObject().asLiteral().getString();
}

private Reader getReader() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cz.cvut.spipes.modules;

import cz.cvut.spipes.constants.CSVW;
import cz.cvut.spipes.engine.ExecutionContext;
import cz.cvut.spipes.engine.ExecutionContextFactory;
import cz.cvut.spipes.exception.ResourceNotUniqueException;
Expand All @@ -12,7 +11,8 @@
import java.io.IOException;
import java.net.URISyntaxException;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TabularModuleTest extends AbstractModuleTestHelper {

Expand All @@ -24,7 +24,7 @@ public String getModuleName() {
}

@BeforeEach
public void init() {
public void setUp() {
module = new TabularModule();

module.setReplace(true);
Expand Down

0 comments on commit 0a896d6

Please sign in to comment.