Check if syntax of URLs / mailto IRI are valid, remove the statement if this isn't the case @param con @throws URISyntaxException
(RepositoryConnection con)
| 1097 | * @throws URISyntaxException |
| 1098 | */ |
| 1099 | private static void checkAllIRIs(RepositoryConnection con) { |
| 1100 | int invalid = 0; |
| 1101 | |
| 1102 | try(RepositoryResult<Statement> res = con.getStatements(null, null, null)) { |
| 1103 | while(res.hasNext()) { |
| 1104 | Statement stmt = res.next(); |
| 1105 | Resource subjRes = stmt.getSubject(); |
| 1106 | boolean remove = false; |
| 1107 | if (subjRes instanceof IRI iri && !isValidIRI(iri)) { |
| 1108 | LOG.error("Invalid or relative subject IRI {}, removing ", stmt); |
| 1109 | remove = true; |
| 1110 | } |
| 1111 | |
| 1112 | Value objRes = stmt.getObject(); |
| 1113 | if (objRes instanceof IRI iri && !isValidIRI(iri)) { |
| 1114 | LOG.error("Invalid or relative object IRI {}, removing", stmt); |
| 1115 | remove = true; |
| 1116 | } |
| 1117 | if (remove) { |
| 1118 | invalid++; |
| 1119 | con.remove(stmt); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | LOG.info("Detected {} invalid IRIs", invalid); |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * Main program |