List of usage examples for java.util Scanner useDelimiter
public Scanner useDelimiter(String pattern)
From source file:org.cyclop.service.importer.intern.AbstractImporter.java
@Override public final ImportStats importScript(InputStream input, ResultWriter resultWriter, ImportConfig config) { LOG.debug("Starting query import"); StopWatch timer = new StopWatch(); timer.start();/* w w w. j a v a 2 s . c o m*/ StatsCollector status = new StatsCollector(); Scanner scanner = new Scanner(input, conf.queryImport.encoding); scanner.useDelimiter(conf.queryImport.listSeparatorRegEx); LOG.debug("Executing import"); execImport(scanner, resultWriter, status, config); timer.stop(); ImportStats stats = new ImportStats(timer, status.success.get(), status.error.get()); LOG.debug("Import done: {}", stats); return stats; }
From source file:EntityToD2RHelpers.java
public EntityToD2RHelpers(String uri, String config_file, List<String> people, List<String> places, PrintWriter out) throws Exception { // In this example, I am assuming that the D2R server is running on localhost:2020 //out.println("PREFIX vocab: <http://localhost:2020/vocab/resource/>"); List<String> lines = (List<String>) FileUtils.readLines(new File(config_file)); String d2r_host_and_port = lines.remove(0); String[] info = d2r_host_and_port.split(" "); System.out.println("D2R host = |" + info[0] + "| and port = |" + info[1] + "|"); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); String d2r_type = scanner.next(); System.out.println("* d2r_type = " + d2r_type); while (scanner.hasNext()) { String term = scanner.next(); String[] property_and_entity_type = term.split("/"); System.out.println(" property: " + property_and_entity_type[0] + " entity type: " + property_and_entity_type[1]); if (property_and_entity_type[1].equals("person")) { for (String person : people) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + person + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("person"); out.println(blank_node + " <http://knowledgebooks.com/rdf/personName> \"" + person.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPerson> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); }// ww w . j a va2 s . c o m } } } else if (property_and_entity_type[1].equals("place")) { for (String place : places) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + place + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("place"); out.println(blank_node + " <http://knowledgebooks.com/rdf/placeName> \"" + place.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPlace> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); } } } } } } out.close(); }
From source file:com.sonicle.webtop.core.versioning.SqlScript.java
private void readFile(InputStreamReader readable) throws IOException { this.statements = new ArrayList<>(); String lines[] = null;//from ww w. j a v a 2s . co m StringBuilder sbsql = null; Scanner s = new Scanner(readable); s.useDelimiter("(;( )?(\r)?\n)"); while (s.hasNext()) { String block = s.next(); block = StringUtils.replace(block, "\r", ""); if (!StringUtils.isEmpty(block)) { // Remove remaining ; at the end of the block (only if this block is the last one) if (!s.hasNext() && StringUtils.endsWith(block, ";")) block = StringUtils.left(block, block.length() - 1); sbsql = new StringBuilder(); lines = StringUtils.split(block, "\n"); for (String line : lines) { if (CommentLine.matches(line)) continue; sbsql.append(StringUtils.trim(line)); sbsql.append(" "); } if (sbsql.length() > 0) statements.add(sbsql.toString()); } } }
From source file:br.cefetrj.sagitarii.nunki.comm.WebClient.java
private String convertStreamToString(java.io.InputStreamReader is) { java.util.Scanner s = new java.util.Scanner(is); s.useDelimiter("\\A"); String retorno = s.hasNext() ? s.next() : ""; s.close();/*from w ww . ja va 2s . com*/ return retorno; }
From source file:org.geppetto.core.model.services.OBJModelInterpreterService.java
@Override public IModel readModel(URL url, List<URL> recordings, String instancePath) throws ModelInterpreterException { ModelWrapper collada = new ModelWrapper(instancePath); try {/* w w w . ja va2 s. c o m*/ Scanner scanner = new Scanner(url.openStream(), "UTF-8"); String objContent = scanner.useDelimiter("\\A").next(); scanner.close(); collada.wrapModel(OBJ, objContent); } catch (IOException e) { throw new ModelInterpreterException(e); } return collada; }
From source file:org.apache.nutch.indexer.html.HtmlIndexingFilter.java
private NutchDocument addRawContent(NutchDocument doc, WebPage page, String url) { ByteBuffer raw = page.getContent(); if (raw != null) { if (LOG.isInfoEnabled()) { LOG.info("Html indexing for: " + url.toString()); }//from w w w .j a v a 2 s .c om ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(raw.array(), raw.arrayOffset() + raw.position(), raw.remaining()); Scanner scanner = new Scanner(arrayInputStream); scanner.useDelimiter("\\Z");//To read all scanner content in one String String data = ""; if (scanner.hasNext()) { data = scanner.next(); } doc.add("rawcontent", StringUtil.cleanField(data)); } return doc; }
From source file:org.geppetto.core.model.services.ColladaModelInterpreterService.java
@Override public IModel readModel(URL url, List<URL> recordings, String instancePath) throws ModelInterpreterException { ModelWrapper collada = new ModelWrapper(instancePath); try {/* w w w.j av a 2s . co m*/ Scanner scanner = new Scanner(url.openStream(), "UTF-8"); String colladaContent = scanner.useDelimiter("\\A").next(); scanner.close(); collada.wrapModel(COLLADA, colladaContent); } catch (IOException e) { throw new ModelInterpreterException(e); } return collada; }
From source file:RdfDataGenerationApplication.java
public RdfDataGenerationApplication(String web_sites_config_file, String database_config_file, PrintWriter out) throws Exception { this.out = out; this.database_config_file = database_config_file; // process web sites: List<String> lines = (List<String>) FileUtils.readLines(new File(web_sites_config_file)); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); try {// w w w .j a v a 2 s .co m String starting_url = scanner.next(); int spider_depth = Integer.parseInt(scanner.next()); spider(starting_url, spider_depth); } catch (Exception ex) { ex.printStackTrace(); } } // after processing all 4 data sources, add more RDF statements for inter-source properties: process_interpage_shared_properties(); out.close(); }
From source file:com.mirth.connect.client.ui.components.rsta.ac.js.PartialHashMap.java
private String[] splitKey(String key) { List<String> list = new ArrayList<String>(); Scanner scanner = new Scanner(key); scanner.useDelimiter(SPLIT_PATTERN); while (scanner.hasNext()) { list.add(scanner.next().toLowerCase()); }/*www. j av a2 s .co m*/ scanner.close(); return list.toArray(new String[list.size()]); }
From source file:org.apache.sysml.api.mlcontext.MLContextUtil.java
/** * Compare two version strings (ie, "1.4.0" and "1.4.1"). * /*from w ww . jav a 2 s. c o m*/ * @param versionStr1 * First version string. * @param versionStr2 * Second version string. * @return If versionStr1 is less than versionStr2, return {@code -1}. If * versionStr1 equals versionStr2, return {@code 0}. If versionStr1 * is greater than versionStr2, return {@code 1}. * @throws MLContextException * if versionStr1 or versionStr2 is {@code null} */ private static int compareVersion(String versionStr1, String versionStr2) { if (versionStr1 == null) { throw new MLContextException("First version argument to compareVersion() is null"); } if (versionStr2 == null) { throw new MLContextException("Second version argument to compareVersion() is null"); } Scanner scanner1 = null; Scanner scanner2 = null; try { scanner1 = new Scanner(versionStr1); scanner2 = new Scanner(versionStr2); scanner1.useDelimiter("\\."); scanner2.useDelimiter("\\."); while (scanner1.hasNextInt() && scanner2.hasNextInt()) { int version1 = scanner1.nextInt(); int version2 = scanner2.nextInt(); if (version1 < version2) { return -1; } else if (version1 > version2) { return 1; } } return scanner1.hasNextInt() ? 1 : 0; } finally { scanner1.close(); scanner2.close(); } }