use of java.util.Scanner in project neo4j by neo4j.
the class LastLocation method getLastLocation.
public static String getLastLocation(String defaultLocation) {
File file = new File(".dblocation");
String location = defaultLocation;
if (file.exists() && file.canRead()) {
try (Scanner scanner = new Scanner(file)) {
if (scanner.hasNextLine()) {
location = scanner.nextLine();
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
}
return location;
}
use of java.util.Scanner in project jphp by jphp-compiler.
the class StrUtils method lines.
@Signature({ @Arg(value = "string"), @Arg(value = "removeEmpty", optional = @Optional("false")) })
public static Memory lines(Environment env, Memory... args) {
boolean removeEmpty = args[1].toBoolean();
Scanner scanner = new Scanner(args[0].toString());
ArrayMemory result = new ArrayMemory();
while (scanner.hasNextLine()) {
String value = scanner.nextLine();
if (removeEmpty) {
value = value.trim();
if (value.isEmpty()) {
continue;
}
}
result.add(value);
}
return result.toConstant();
}
use of java.util.Scanner in project orientdb by orientechnologies.
the class OScriptManager method throwErrorMessage.
public String throwErrorMessage(final ScriptException e, final String lib) {
int errorLineNumber = e.getLineNumber();
if (errorLineNumber <= 0) {
// FIX TO RHINO: SOMETIMES HAS THE LINE NUMBER INSIDE THE TEXT :-(
final String excMessage = e.toString();
final int pos = excMessage.indexOf("<Unknown Source>#");
if (pos > -1) {
final int end = excMessage.indexOf(')', pos + "<Unknown Source>#".length());
String lineNumberAsString = excMessage.substring(pos + "<Unknown Source>#".length(), end);
errorLineNumber = Integer.parseInt(lineNumberAsString);
}
}
if (errorLineNumber <= 0) {
throw new OCommandScriptException("Error on evaluation of the script library. Error: " + e.getMessage() + "\nScript library was:\n" + lib);
} else {
final StringBuilder code = new StringBuilder();
final Scanner scanner = new Scanner(lib);
try {
scanner.useDelimiter("\n");
String currentLine = null;
String lastFunctionName = "unknown";
for (int currentLineNumber = 1; scanner.hasNext(); currentLineNumber++) {
currentLine = scanner.next();
int pos = currentLine.indexOf("function");
if (pos > -1) {
final String[] words = OStringParser.getWords(currentLine.substring(Math.min(pos + "function".length() + 1, currentLine.length())), " \r\n\t");
if (words.length > 0 && words[0] != "(")
lastFunctionName = words[0];
}
if (currentLineNumber == errorLineNumber)
// APPEND X LINES BEFORE
code.append(String.format("%4d: >>> %s\n", currentLineNumber, currentLine));
else if (Math.abs(currentLineNumber - errorLineNumber) <= LINES_AROUND_ERROR)
// AROUND: APPEND IT
code.append(String.format("%4d: %s\n", currentLineNumber, currentLine));
}
code.insert(0, String.format("ScriptManager: error %s.\nFunction %s:\n\n", e.getMessage(), lastFunctionName));
} finally {
scanner.close();
}
throw new OCommandScriptException(code.toString());
}
}
use of java.util.Scanner in project textdb by TextDB.
the class POSTagexample method main.
public static void main(String[] args) throws IOException {
POSModel model = new POSModelLoader().load(new File("./src/main/java/edu/uci/ics/textdb/sandbox/OpenNLPexample/en-pos-maxent.bin"));
PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
POSTaggerME tagger = new POSTaggerME(model);
String dataFile = "./src/main/resources/abstract_100.txt";
Scanner scan = new Scanner(new File(dataFile));
int counter = 0;
perfMon.start();
while (scan.hasNextLine()) {
String input = scan.nextLine();
String[] sentence = Tokenize(input);
String[] tags = tagger.tag(sentence);
perfMon.incrementCounter();
for (int i = 0; i < sentence.length; i++) {
String word = sentence[i];
String pos = tags[i];
//filter out useless results
if (!word.equals(pos) && !pos.equals("``") && !pos.equals("''")) {
counter++;
System.out.println("word: " + sentence[i] + " pos: " + tags[i]);
}
}
}
System.out.println("Total Number of Results: " + counter);
perfMon.stopAndPrintFinalResult();
scan.close();
}
use of java.util.Scanner in project textdb by TextDB.
the class SampleExtraction method writeSampleIndex.
public static void writeSampleIndex() throws Exception {
// parse the original file
File sourceFileFolder = new File(promedFilesDirectory);
ArrayList<Tuple> fileTuples = new ArrayList<>();
for (File htmlFile : sourceFileFolder.listFiles()) {
StringBuilder sb = new StringBuilder();
Scanner scanner = new Scanner(htmlFile);
while (scanner.hasNext()) {
sb.append(scanner.nextLine());
}
scanner.close();
Tuple tuple = parsePromedHTML(htmlFile.getName(), sb.toString());
if (tuple != null) {
fileTuples.add(tuple);
}
}
// write tuples into the table
RelationManager relationManager = RelationManager.getRelationManager();
relationManager.deleteTable(PROMED_SAMPLE_TABLE);
relationManager.createTable(PROMED_SAMPLE_TABLE, promedIndexDirectory, PromedSchema.PROMED_SCHEMA, LuceneAnalyzerConstants.standardAnalyzerString());
DataWriter dataWriter = relationManager.getTableDataWriter(PROMED_SAMPLE_TABLE);
dataWriter.open();
for (Tuple tuple : fileTuples) {
dataWriter.insertTuple(tuple);
}
dataWriter.close();
}
Aggregations