From 7ad0f2d35792d74b7ffe450f98352e1581e2b05a Mon Sep 17 00:00:00 2001 From: Miroslav Blasko Date: Mon, 6 Jan 2025 18:18:38 +0100 Subject: [PATCH] Reformat --- .../cz/cvut/spipes/modules/TabularModule.java | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java index 0316249a..919b34ea 100644 --- a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java +++ b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java @@ -13,7 +13,6 @@ import cz.cvut.spipes.exception.ResourceNotUniqueException; import cz.cvut.spipes.exception.SPipesException; import cz.cvut.spipes.modules.annotations.SPipesModule; -import cz.cvut.spipes.modules.exception.SheetDoesntExistsException; import cz.cvut.spipes.modules.exception.SheetIsNotSpecifiedException; import cz.cvut.spipes.modules.exception.SpecificationNonComplianceException; import cz.cvut.spipes.modules.handlers.ModeHandler; @@ -31,6 +30,7 @@ import org.supercsv.io.ICsvListReader; import org.supercsv.prefs.CsvPreference; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.Reader; import java.io.StringReader; @@ -113,12 +113,12 @@ public class TabularModule extends AnnotatedAbstractModule { private final Property P_PROCESS_TABLE_AT_INDEX = getSpecificParameter("process-table-at-index"); @Parameter(iri = SML.replace, comment = "Specifies whether a module should overwrite triples" + - " from its predecessors. When set to true (default is false), it prevents" + - " passing through triples from the predecessors.") + " from its predecessors. When set to true (default is false), it prevents" + + " passing through triples from the predecessors.") private boolean isReplace = false; @Parameter(iri = PARAM_URL_PREFIX + "source-resource-uri", comment = "URI of resource" + - " that represent tabular data (e.g. resource representing CSV file).") + " that represent tabular data (e.g. resource representing CSV file).") private StreamResource sourceResource; @Parameter(iri = PARAM_URL_PREFIX + "delimiter", comment = "Column delimiter. Default value is comma ','.") @@ -281,9 +281,9 @@ ExecutionContext executeSelf() { tableSchema.setAboutUrl(schemaColumn, sourceResource.getUri()); schemaColumn.setProperty( - dataPrefix, - sourceResource.getUri(), - hasInputSchema ? tableSchema.getColumn(columnName) : null); + dataPrefix, + sourceResource.getUri(), + hasInputSchema ? tableSchema.getColumn(columnName) : null); schemaColumn.setTitle(columnTitle); if (isDuplicate) throwNotUniqueException(schemaColumn, columnTitle, columnName); } @@ -337,10 +337,10 @@ ExecutionContext executeSelf() { tableSchema.adjustProperties(hasInputSchema, outputColumns, sourceResource.getUri()); tableSchema.setColumnsSet(new HashSet<>(outputColumns)); - em = JopaPersistenceUtils.getEntityManager("cz.cvut.spipes.modules.model", outputModel); - em.getTransaction().begin(); - em.persist(tableGroup); - em.merge(tableSchema); + em = JopaPersistenceUtils.getEntityManager("cz.cvut.spipes.modules.model", outputModel); + em.getTransaction().begin(); + em.persist(tableGroup); + em.merge(tableSchema); if (tsvConvertor != null) { List regions = tsvConvertor.getMergedRegions(originalSourceResource); @@ -348,13 +348,14 @@ ExecutionContext executeSelf() { int cellsNum = 1; for (Region region : regions) { int firstCellInRegionNum = cellsNum; - for(int i = region.getFirstRow();i <= region.getLastRow();i++){ - for(int j = region.getFirstColumn();j <= region.getLastColumn();j++) { - Cell cell = new Cell(sourceResource.getUri()+"#cell"+(cellsNum)); + for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) { + for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) { + Cell cell = new Cell(sourceResource.getUri() + "#cell" + cellsNum); cell.setRow(tableSchema.createAboutUrl(i)); cell.setColumn(outputColumns.get(j).getUri().toString()); - if(cellsNum != firstCellInRegionNum) - cell.setSameValueAsCell(sourceResource.getUri()+"#cell"+(firstCellInRegionNum)); + if (cellsNum != firstCellInRegionNum) { + cell.setSameValueAsCell(sourceResource.getUri() + "#cell" + firstCellInRegionNum); + } em.merge(cell); cellsNum++; } @@ -381,19 +382,19 @@ private String getValueFromRow(List row, int index, int expectedRowLengt StringBuilder record = new StringBuilder(recordDelimiter); for (int i = 0; i < row.size(); i++) { record - .append(i) - .append(":") - .append(row.get(i)) - .append(recordDelimiter); + .append(i) + .append(":") + .append(row.get(i)) + .append(recordDelimiter); } LOG.error("Reading input file failed when reading record #{} (may not reflect the line #).\n" + - " It was expected that the current record contains {} values" + - ", but {}. element was not retrieved before whole record was processed.\n" + - "The problematic record: {}", - currentRecordNumber, - expectedRowLength, - index+1, - record + " It was expected that the current record contains {} values" + + ", but {}. element was not retrieved before whole record was processed.\n" + + "The problematic record: {}", + currentRecordNumber, + expectedRowLength, + index+1, + record ); throw new SPipesException("Reading input file failed.", e); } @@ -413,9 +414,9 @@ private Statement createRowResource(String cellValue, int rowNumber, Column colu Resource rowResource = ResourceFactory.createResource(tableSchema.createAboutUrl(rowNumber)); return ResourceFactory.createStatement( - rowResource, - ResourceFactory.createProperty(column.getPropertyUrl()), - ResourceFactory.createPlainLiteral(cellValue)); + rowResource, + ResourceFactory.createProperty(column.getPropertyUrl()), + ResourceFactory.createPlainLiteral(cellValue)); } private boolean hasInputSchema(TableSchema inputTableSchema) { @@ -429,11 +430,11 @@ private boolean hasInputSchema(TableSchema inputTableSchema) { private TableSchema getTableSchema(EntityManager em) { TypedQuery query = em.createNativeQuery( - "PREFIX csvw: \n" + - "SELECT ?t WHERE { \n" + - "?t a csvw:TableSchema. \n" + - "}", - TableSchema.class + "PREFIX csvw: \n" + + "SELECT ?t WHERE { \n" + + "?t a csvw:TableSchema. \n" + + "}", + TableSchema.class ); int tableSchemaCount = query.getResultList().size(); @@ -452,14 +453,14 @@ private TableSchema getTableSchema(EntityManager em) { private void throwNotUniqueException(Column column, String columnTitle, String columnName) { throw new ResourceNotUniqueException( - String.format("Unable to create value of property %s due to collision. " + - "Both column titles '%s' and '%s' are normalized to '%s' " + - "and thus would refer to the same property url <%s>.", - CSVW.propertyUrl, - columnTitle, - column.getTitle(), - columnName, - column.getPropertyUrl())); + String.format("Unable to create value of property %s due to collision. " + + "Both column titles '%s' and '%s' are normalized to '%s' " + + "and thus would refer to the same property url <%s>.", + CSVW.propertyUrl, + columnTitle, + column.getTitle(), + columnName, + column.getPropertyUrl())); } private ExecutionContext getExecutionContext(Model inputModel, Model outputModel) { @@ -473,12 +474,12 @@ private ExecutionContext getExecutionContext(Model inputModel, Model outputModel @Override public void loadManualConfiguration() { sourceResourceFormat = ResourceFormat.fromString( - getPropertyValue(P_SOURCE_RESOURCE_FORMAT, ResourceFormat.PLAIN.getValue()) + getPropertyValue(P_SOURCE_RESOURCE_FORMAT, ResourceFormat.PLAIN.getValue()) ); delimiter = getPropertyValue(P_DELIMITER, getDefaultDelimiterSupplier(sourceResourceFormat)); quoteCharacter = getPropertyValue(P_QUOTE_CHARACTER, getDefaultQuoteCharacterSupplier(sourceResourceFormat)); outputMode = Mode.fromResource( - getPropertyValue(P_OUTPUT_MODE, Mode.STANDARD.getResource()) + getPropertyValue(P_OUTPUT_MODE, Mode.STANDARD.getResource()) ); setInputCharset(delimiter); } @@ -514,7 +515,7 @@ private Supplier getDefaultQuoteCharacterSupplier(ResourceFormat sour if (sourceResourceFormat == ResourceFormat.CSV) { return () -> { LOG.debug("Quote character not specified, using double-quote as default value" + - " to be compliant with RFC 4180 (CSV)"); + " to be compliant with RFC 4180 (CSV)"); return '"'; }; } @@ -524,8 +525,8 @@ private Supplier getDefaultQuoteCharacterSupplier(ResourceFormat sour private char getPropertyValue(Property property, Supplier defaultValueSupplier) { return Optional.ofNullable(getPropertyValue(property)) - .map(n -> n.asLiteral().getChar()) - .orElseGet(defaultValueSupplier); + .map(n -> n.asLiteral().getChar()) + .orElseGet(defaultValueSupplier); } @Override @@ -624,7 +625,7 @@ public int getDelimiter() { public void setDelimiter(int delimiter) { if ((sourceResourceFormat == ResourceFormat.CSV && delimiter != ',') || - (sourceResourceFormat == ResourceFormat.TSV && delimiter != '\t')) { + (sourceResourceFormat == ResourceFormat.TSV && delimiter != '\t')) { throw new SpecificationNonComplianceException(sourceResourceFormat, delimiter); } this.delimiter = delimiter;