DoReasonTask6 extends CommonTask { protected int inferAndSaveTriplesToFile(QueryResult queryResult, Set<String> productiveTerms, String table, PrintWriter writer) throws IOException { log.info("********************** Starting Inference Round **********************"); int inferredTriples = 0; try (BufferedReader r = new BufferedReader(new FileReader(queryResult.getFilename()), Constants.GZIP_BUF_SIZE)) { Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(r); try { String term; for (CSVRecord record : records) { NTriple instanceTriple = (NTriple) NTriple.fromCSV(record.values()); if(SchemaURIType.RDF_TYPE.getUri().equals(instanceTriple.getPredicate())) { term = instanceTriple.getObject(); } else { term = instanceTriple.getPredicate(); } Set<Triple> schemaTriples = schemaTerms.get(term); if((schemaTriples != null) && !schemaTriples.isEmpty()) { productiveTerms.add(term); for(Triple schemaTriple: schemaTriples) { Rule rule = GenericRule.getRule(schemaTriple); Triple inferredTriple = rule.head(schemaTriple, instanceTriple); if(inferredTriple != null) { writer.println(inferredTriple.toCsv()); inferredTriples++; } } } } } catch(Exception e) { log.error("Failed to parse selected terms", e); throw new IOException(e); } } log.info("Total Rows: " + queryResult.getStats().getTotalRows() + ", Total Processed Bytes: " + queryResult.getStats().getTotalProcessedGBytes() + " GB" + ", Inferred: " + inferredTriples); log.info("********************** Completed Inference Round **********************"); return inferredTriples; }  @Override void run(); String getTable(); void setTable(String table); String getSchemaFile(); void setSchemaFile(String schemaFile); String getTerms(); void setTerms(String terms); String getTermsFile(); void setTermsFile(String termsFile); String getBucket(); void setBucket(String bucket);  }
@Test public void testInferAndSaveTriplesToFile() throws FileNotFoundException, IOException { this.doTestInferAndSaveTriplesToFile("/schema.nt", "/inferred.nt"); this.doTestInferAndSaveTriplesToFile("/schema1.nt", "/inferred1.nt"); }