Search in sources :

Example 91 with Scanner

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;
}
Also used : Scanner(java.util.Scanner) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 92 with Scanner

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();
}
Also used : Scanner(java.util.Scanner)

Example 93 with Scanner

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());
    }
}
Also used : Scanner(java.util.Scanner)

Example 94 with Scanner

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();
}
Also used : Scanner(java.util.Scanner) POSModel(opennlp.tools.postag.POSModel) POSTaggerME(opennlp.tools.postag.POSTaggerME) PerformanceMonitor(opennlp.tools.cmdline.PerformanceMonitor) POSModelLoader(opennlp.tools.cmdline.postag.POSModelLoader) File(java.io.File)

Example 95 with Scanner

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();
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) File(java.io.File) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) RelationManager(edu.uci.ics.textdb.storage.RelationManager) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Aggregations

Scanner (java.util.Scanner)862 File (java.io.File)135 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)72 Test (org.junit.Test)70 NoSuchElementException (java.util.NoSuchElementException)59 InputStream (java.io.InputStream)54 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 FileNotFoundException (java.io.FileNotFoundException)47 InputMismatchException (java.util.InputMismatchException)47 HashMap (java.util.HashMap)35 FileInputStream (java.io.FileInputStream)33 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 Locale (java.util.Locale)24 BigInteger (java.math.BigInteger)23 List (java.util.List)22 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18