Example usage for java.util Scanner hasNextLine

List of usage examples for java.util Scanner hasNextLine

Introduction

In this page you can find the example usage for java.util Scanner hasNextLine.

Prototype

public boolean hasNextLine() 

Source Link

Document

Returns true if there is another line in the input of this scanner.

Usage

From source file:com.joliciel.talismane.extensions.standoff.StandoffReader.java

public StandoffReader(TalismaneSession talismaneSession, Scanner scanner) {
    this.talismaneSession = talismaneSession;
    PosTagSet posTagSet = talismaneSession.getPosTagSet();

    Map<Integer, StandoffToken> sortedTokens = new TreeMap<Integer, StandoffReader.StandoffToken>();
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (line.startsWith("T")) {

            String[] parts = line.split("[\\t]");
            String id = parts[0];
            String[] posTagParts = parts[1].split(" ");
            String posTagCode = posTagParts[0].replace('_', '+');
            int startPos = Integer.parseInt(posTagParts[1]);
            String text = parts[2];

            PosTag posTag = null;//  w w  w.  j a va2s . c om
            if (posTagCode.equalsIgnoreCase(PosTag.ROOT_POS_TAG_CODE)) {
                posTag = PosTag.ROOT_POS_TAG;
            } else {
                try {
                    posTag = posTagSet.getPosTag(posTagCode);
                } catch (UnknownPosTagException upte) {
                    throw new TalismaneException("Unknown posTag on line " + lineNumber + ": " + posTagCode);
                }
            }

            StandoffToken token = new StandoffToken();
            token.posTag = posTag;
            token.text = text;
            token.id = id;

            sortedTokens.put(startPos, token);
            tokenMap.put(id, token);

        } else if (line.startsWith("R")) {

            String[] parts = line.split("[\\t :]");
            String id = parts[0];
            String label = parts[1];
            String headId = parts[3];
            String dependentId = parts[5];
            StandoffRelation relation = new StandoffRelation();
            relation.fromToken = headId;
            relation.toToken = dependentId;
            relation.label = label;
            idRelationMap.put(id, relation);
            relationMap.put(dependentId, relation);
        } else if (line.startsWith("#")) {
            String[] parts = line.split("\t");
            String itemId = parts[1].substring("AnnotatorNotes ".length());
            String note = parts[2];
            notes.put(itemId, note);
        }
    }

    for (String itemId : notes.keySet()) {
        String comment = notes.get(itemId);
        if (itemId.startsWith("R")) {
            StandoffRelation relation = idRelationMap.get(itemId);
            relation.comment = comment;
        } else {
            StandoffToken token = tokenMap.get(itemId);
            token.comment = comment;
        }
    }

    List<StandoffToken> currentSentence = null;
    for (StandoffToken token : sortedTokens.values()) {
        if (token.text.equals("ROOT")) {
            if (currentSentence != null)
                sentences.add(currentSentence);
            currentSentence = new ArrayList<StandoffReader.StandoffToken>();
        }
        currentSentence.add(token);
    }
    if (currentSentence != null)
        sentences.add(currentSentence);
}

From source file:edu.harvard.med.iccbl.screensaver.io.screens.ScreenPrivacyExpirationUpdater.java

/**
 * Return the subject first and the message second.
 * Message:/*w  w w.  j a v  a2s .c  om*/
 * {0} Screen Number
 * {1} Screen Title
 * {2} timeToNotify (tbd, formatting)
 * 
 * @throws MessagingException
 */
private Pair<String, String> getScreenExpireNotificationSubjectMessage() throws MessagingException {
    InputStream in = null;
    if (isCommandLineFlagSet(EXPIRATION_EMAIL_MESSAGE_LOCATION[SHORT_OPTION_INDEX])) {
        try {
            in = new FileInputStream(
                    new File(getCommandLineOptionValue(EXPIRATION_EMAIL_MESSAGE_LOCATION[SHORT_OPTION_INDEX])));
        } catch (FileNotFoundException e) {
            sendErrorMail(
                    "Operation not completed for ScreenPrivacyExpirationUpdater, could not locate expiration message",
                    toString(), e);
            throw new DAOTransactionRollbackException(e);
        }
    } else {
        in = this.getClass().getResourceAsStream(EXPIRATION_MESSAGE_TXT_LOCATION);
    }
    Scanner scanner = new Scanner(in);
    try {
        StringBuilder builder = new StringBuilder();
        String subject = scanner.nextLine(); // first line is the subject
        while (scanner.hasNextLine()) {
            builder.append(scanner.nextLine()).append("\n");
        }
        return Pair.newPair(subject, builder.toString());
    } finally {
        scanner.close();
    }
}

From source file:com.smi.travel.monitor.MonitorGalileo.java

@Override
void buildContentList(String file) {
    String galiFile = this.monitorDirectory + file;
    Path fFilePath;//  ww w  . j  a v  a  2s  .c  o  m
    fFilePath = Paths.get(galiFile);

    lineData = new ArrayList<String>();
    lineData.add("");
    sectionData = new MultiValueMap();

    Scanner scanner = null;
    try {
        scanner = new Scanner(fFilePath, ENCODING.name());

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            //                System.out.println(line);

            if (line.matches(MonitorGalileo.SECTION_PATTERN)) {
                String key = line.substring(0, 3);
                //                    System.out.println("Key " + key + " ** Line " + line);
                sectionData.put(key, line);

            } else {
                lineData.add(line);
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}

From source file:carmen.LocationResolver.java

/**
 * /*from ww  w. jav a  2 s . c  om*/
 * @param fileName
 * @param splitOn
 * @return
 * @throws IOException 
 */
protected HashMap<String, Integer> loadLocationToIdFile(String filename) throws IOException {
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    Scanner inputScanner = new Scanner(new FileInputStream(filename), "UTF-8");
    int lineNumber = 0;
    while (inputScanner.hasNextLine()) {
        lineNumber++;
        String line = null;
        try {
            line = inputScanner.nextLine().toLowerCase();
            String[] splitString = line.split("\t");
            int locationId = Integer.parseInt(splitString[0].trim());
            for (int ii = 1; ii < splitString.length; ii++) {
                String entry = splitString[ii].trim();
                // Check for duplicates.
                if (map.containsKey(entry) && !map.get(entry).equals(locationId)) {
                    logger.warn("Duplicate location found: " + entry);
                }
                map.put(entry, locationId);
            }
        } catch (Exception e) {
            logger.warn("Error in location to id file line " + lineNumber + ": " + filename + ";" + line);
        }
    }
    inputScanner.close();
    return map;
}

From source file:com.joliciel.talismane.machineLearning.perceptron.PerceptronClassifactionModelTrainerImpl.java

void train() {
    try {//w  w w . j  av  a2s. c  om
        double prevAccuracy1 = 0.0;
        double prevAccuracy2 = 0.0;
        double prevAccuracy3 = 0.0;
        int i = 0;
        int averagingCount = 0;
        for (i = 1; i <= iterations; i++) {
            LOG.debug("Iteration " + i);
            int totalErrors = 0;
            int totalEvents = 0;

            Scanner scanner = new Scanner(
                    new BufferedReader(new InputStreamReader(new FileInputStream(eventFile), "UTF-8")));

            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                PerceptronEvent event = new PerceptronEvent(line);
                totalEvents++;

                // don't normalise unless we calculate the log-likelihood, to avoid mathematical cost of normalising
                double[] results = decisionMaker.predict(event.getFeatureIndexes(), event.getFeatureValues());
                double maxValue = results[0];
                int predicted = 0;
                for (int j = 1; j < results.length; j++) {
                    if (results[j] > maxValue) {
                        maxValue = results[j];
                        predicted = j;
                    }
                }

                int actual = event.getOutcomeIndex();

                if (actual != predicted) {
                    for (int j = 0; j < event.getFeatureIndexes().size(); j++) {
                        double[] classWeights = params.getFeatureWeights()[event.getFeatureIndexes().get(j)];
                        classWeights[actual] += event.getFeatureValues().get(j);
                        classWeights[predicted] -= event.getFeatureValues().get(j);
                    }
                    totalErrors++;
                } // correct outcome?
            } // next event

            // Add feature weights for this iteration
            boolean addAverage = true;
            if (this.isAverageAtIntervals()) {
                if (i <= 20 || i == 25 || i == 36 || i == 49 || i == 64 || i == 81 || i == 100 || i == 121
                        || i == 144 || i == 169 || i == 196) {
                    addAverage = true;
                    LOG.debug("Averaging at iteration: " + i);
                } else
                    addAverage = false;
            }

            if (addAverage) {
                for (int j = 0; j < params.getFeatureWeights().length; j++) {
                    double[] totalClassWeights = totalFeatureWeights[j];
                    double[] classWeights = params.getFeatureWeights()[j];
                    for (int k = 0; k < params.getOutcomeCount(); k++) {
                        totalClassWeights[k] += classWeights[k];
                    }
                }
                averagingCount++;
            }

            if (observer != null && observationPoints.contains(i)) {
                PerceptronModelParameters cloneParams = params.clone();
                // average the weights for this model
                for (int j = 0; j < cloneParams.getFeatureWeights().length; j++) {
                    double[] totalClassWeights = totalFeatureWeights[j];
                    double[] classWeights = cloneParams.getFeatureWeights()[j];
                    for (int k = 0; k < cloneParams.getOutcomeCount(); k++) {
                        classWeights[k] = totalClassWeights[k] / averagingCount;
                    }
                }
                ClassificationModel<T> model = this.getModel(cloneParams, i);
                observer.onNextModel(model, i);
                cloneParams = null;
            }

            double accuracy = (double) (totalEvents - totalErrors) / (double) totalEvents;
            LOG.debug("Accuracy: " + accuracy);

            // exit if accuracy hasn't significantly changed in 3 iterations
            if (Math.abs(accuracy - prevAccuracy1) < tolerance && Math.abs(accuracy - prevAccuracy2) < tolerance
                    && Math.abs(accuracy - prevAccuracy3) < tolerance) {
                LOG.info("Accuracy change < " + tolerance + " for 3 iterations: exiting after " + i
                        + " iterations");
                break;
            }

            prevAccuracy3 = prevAccuracy2;
            prevAccuracy2 = prevAccuracy1;
            prevAccuracy1 = accuracy;
        } // next iteration

        // average the final weights
        for (int j = 0; j < params.getFeatureWeights().length; j++) {
            double[] totalClassWeights = totalFeatureWeights[j];
            double[] classWeights = params.getFeatureWeights()[j];
            for (int k = 0; k < params.getOutcomeCount(); k++) {
                classWeights[k] = totalClassWeights[k] / averagingCount;
            }
        }

    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:com.joliciel.jochre.search.JochreIndexBuilderImpl.java

private void updateDocumentInternal(File documentDir) {
    try {//from   w  w w  .  j  ava2 s  . com
        LOG.info("Updating index for " + documentDir.getName());

        File zipFile = new File(documentDir, documentDir.getName() + ".zip");
        if (!zipFile.exists()) {
            LOG.info("Nothing to index in " + documentDir.getName());
            return;
        }
        long zipDate = zipFile.lastModified();

        this.deleteDocumentInternal(documentDir);

        File[] offsetFiles = documentDir.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".obj");
            }
        });

        for (File offsetFile : offsetFiles) {
            offsetFile.delete();
        }

        int i = 0;

        Map<String, String> fields = new TreeMap<String, String>();
        File metaDataFile = new File(documentDir, "metadata.txt");
        Scanner scanner = new Scanner(
                new BufferedReader(new InputStreamReader(new FileInputStream(metaDataFile), "UTF-8")));
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            String key = line.substring(0, line.indexOf('\t'));
            String value = line.substring(line.indexOf('\t'));
            fields.put(key, value);
        }
        scanner.close();

        JochreXmlDocument xmlDoc = this.searchService.newDocument();
        JochreXmlReader reader = this.searchService.getJochreXmlReader(xmlDoc);

        ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
        ZipEntry ze = null;
        while ((ze = zis.getNextEntry()) != null) {
            LOG.debug("Adding zipEntry " + i + ": " + ze.getName());
            String baseName = ze.getName().substring(0, ze.getName().lastIndexOf('.'));
            UnclosableInputStream uis = new UnclosableInputStream(zis);
            reader.parseFile(uis, baseName);
            i++;
        }
        zis.close();

        i = 0;
        StringBuilder sb = new StringBuilder();
        coordinateStorage = searchService.getCoordinateStorage();
        offsetLetterMap = new HashMap<Integer, JochreXmlLetter>();
        int startPage = -1;
        int endPage = -1;
        int docCount = 0;
        int wordCount = 0;
        int cumulWordCount = 0;
        for (JochreXmlImage image : xmlDoc.getImages()) {
            if (startPage < 0)
                startPage = image.getPageIndex();
            endPage = image.getPageIndex();
            int remainingWords = xmlDoc.wordCount() - (cumulWordCount + wordCount);
            LOG.debug("Word count: " + wordCount + ", cumul word count: " + cumulWordCount
                    + ", total xml words: " + xmlDoc.wordCount() + ", remaining words: " + remainingWords);
            if (wordsPerDoc > 0 && wordCount >= wordsPerDoc && remainingWords >= wordsPerDoc) {
                LOG.debug("Creating new index doc: " + docCount);
                JochreIndexDocument indexDoc = searchService.newJochreIndexDocument(documentDir, docCount, sb,
                        coordinateStorage, startPage, endPage, fields);
                indexDoc.save(indexWriter);
                docCount++;

                sb = new StringBuilder();
                coordinateStorage = searchService.getCoordinateStorage();
                startPage = image.getPageIndex();
                offsetLetterMap = new HashMap<Integer, JochreXmlLetter>();
                cumulWordCount += wordCount;
                wordCount = 0;
            }

            LOG.debug("Processing page: " + image.getFileNameBase());

            File imageFile = null;
            for (String imageExtension : imageExtensions) {
                imageFile = new File(documentDir, image.getFileNameBase() + "." + imageExtension);
                if (imageFile.exists())
                    break;
                imageFile = null;
            }
            if (imageFile == null)
                throw new RuntimeException("No image found in directory " + documentDir.getAbsolutePath()
                        + ", baseName " + image.getFileNameBase());

            coordinateStorage.addImage(sb.length(), imageFile.getName(), image.getPageIndex());

            for (JochreXmlParagraph par : image.getParagraphs()) {
                coordinateStorage.addParagraph(sb.length(),
                        new Rectangle(par.getLeft(), par.getTop(), par.getRight(), par.getBottom()));
                for (JochreXmlRow row : par.getRows()) {
                    coordinateStorage.addRow(sb.length(),
                            new Rectangle(row.getLeft(), row.getTop(), row.getRight(), row.getBottom()));
                    int k = 0;
                    for (JochreXmlWord word : row.getWords()) {
                        wordCount++;
                        for (JochreXmlLetter letter : word.getLetters()) {
                            offsetLetterMap.put(sb.length(), letter);
                            if (letter.getText().length() > 1) {
                                for (int j = 1; j < letter.getText().length(); j++) {
                                    offsetLetterMap.put(sb.length() + j, letter);
                                }
                            }
                            sb.append(letter.getText());
                        }
                        k++;
                        boolean finalDash = false;
                        if (k == row.getWords().size() && word.getText().endsWith("-")
                                && word.getText().length() > 1)
                            finalDash = true;
                        if (!finalDash)
                            sb.append(" ");
                    }
                }
                sb.append("\n");
            }
            i++;
        }
        JochreIndexDocument indexDoc = searchService.newJochreIndexDocument(documentDir, docCount, sb,
                coordinateStorage, startPage, endPage, fields);
        indexDoc.save(indexWriter);

        File lastIndexDateFile = new File(documentDir, "indexDate.txt");

        Writer writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(lastIndexDateFile, false), "UTF8"));
        writer.write("" + zipDate);
        writer.flush();

        writer.close();
    } catch (IOException ioe) {
        LogUtils.logError(LOG, ioe);
        throw new RuntimeException(ioe);
    }
}

From source file:de.uzk.hki.da.grid.IrodsCommandLineConnector.java

/**
 * Gets checksum from ICAT for the newest instance destDao
 * @author Jens Peters/*ww  w .j  av  a2  s  .  com*/
 * @param destDao
 * @return
 */
public String getChecksum(String destDao) {
    String ret = "";
    String commandAsArray[] = new String[] { "ichksum", destDao };
    String out = executeIcommand(commandAsArray);
    if (out.indexOf("ERROR") >= 0)
        throw new RuntimeException(" Get Checksum of " + destDao + " failed !");
    Scanner scanner = new Scanner(out);
    String data_name = FilenameUtils.getName(destDao);
    if (data_name.length() > 30)
        data_name = data_name.substring(0, 30);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (line.contains(data_name)) {
            ret = line.substring(38, line.length());
        }
    }
    scanner.close();
    return ret;
}

From source file:com.kdmanalytics.toif.adaptor.SplintAdaptor.java

@Override
public ArrayList<Element> parse(File process, AdaptorOptions options, IFileResolver resolver,
        boolean[] validLines, boolean unknownCWE) throws ToifException {
    com.kdmanalytics.toif.framework.xmlElements.entities.File file = resolver.getDefaultFile();
    // new finding creator
    final FindingCreator creator = new FindingCreator(getProperties(), getAdaptorName(), unknownCWE);

    Scanner scanner = null;
    try {//from   w ww.  j  a va  2s.  com
        scanner = new Scanner(new FileInputStream(process));
        // read from the csv file.
        while (scanner.hasNextLine()) {
            final String csvLine = scanner.nextLine();

            final String[] csvElements = csvLine.split(",");

            // Check if line is valid for parsing
            if (csvElements.length <= 2)
                continue;

            if ("preproc".equals(csvElements[2])) {
                continue;
            }
            // the first line of these csv files have the information of
            // what the values are. We dont need this.
            if ("Warning".equals(csvElements[0])) {
                continue;
            }

            if (csvElements.length < 8) {
                continue;
            }

            // continue if not same file.
            String csvFileName = new File(csvElements[4]).getName();
            String inputFileName = new File(file.getPath()).getName();
            if (!csvFileName.endsWith(inputFileName)) {
                continue;
            }

            // get the weakness description
            String msg = csvElements[7];
            if (msg.startsWith("\"")) {
                msg = msg.substring(1, msg.length());
            }
            if (msg.endsWith("\"")) {
                msg = msg.substring(0, msg.length() - 1);
            }

            if (msg.trim().startsWith("Parse Error")) {
                try {
                    writeToFile("splint: " + msg + "\n");
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                continue;
            }

            // get the weakness id.
            final String id = csvElements[2];
            // get the linenumber of the weakness.
            final Integer lineNumber = Integer.valueOf(csvElements[5]);
            // this tool has no offset.
            final Integer offset = null;
            // get the position of the weakness.
            final Integer position = Integer.valueOf(csvElements[6]);

            // if there is a dataElement, use it.
            String dataElement = null;
            if (msg.split(":").length == 2) {
                dataElement = msg.split(":")[1].trim();
            }

            // if there are valid lines
            if (validLines != null) {
                if (lineNumber > 0) {
                    // return if the line number is greater than the array
                    // size.
                    if (lineNumber < validLines.length) {
                        if (validLines[lineNumber]) {
                            // pass the required information to the finding
                            // creator.
                            creator.create(StringEscapeUtils.unescapeHtml4(msg), id, lineNumber, offset,
                                    position, file, dataElement, null);
                        } else {
                            try {
                                FindingCreator.writeToFile("Splint: Not a valid line (uncompiled) "
                                        + file.getPath() + ":" + lineNumber + "\n");
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                }

            } else {
                // pass the required information to the finding creator.
                creator.create(StringEscapeUtils.unescapeHtml4(msg), id, lineNumber, offset, position, file,
                        dataElement, null);
            }

            // // pass the required information to the finding creator.
            // creator.create(StringEscapeUtils.unescapeHtml4(msg), id,
            // lineNumber, offset, position, file, dataElement, null);
            //
            //
            // // if there are valid lines
            // if (validLines != null)
            // {
            // // return if the line number is greater than the array size.
            // if (lineNumber < validLines.length)
            // {
            // if (validLines[lineNumber])
            // {
            // // create the finding.
            // creator.create(StringEscapeUtils.unescapeHtml4(msg), id,
            // lineNumber, offset, position, file, dataElement, null);
            // }
            // }
            //
            // }

        }

        // delete the file we made in the tmp directory.
        // tmpFile.delete();
    } catch (final FileNotFoundException e) {
        final String msg = "The tools output file could not be found. \"" + tmpFile.getAbsolutePath() + '"';
        LOG.error(msg, e);
        throw new ToifException(msg, e);
    } finally {
        if (scanner != null)
            scanner.close();
    }

    // return the elements from the finding creator.
    return creator.getElements();
}

From source file:com.alibaba.dubbo.qos.textui.TTable.java

private String drawRow(int[] widthCacheArray, int rowIndex) {

    final StringBuilder rowSB = new StringBuilder();
    final Scanner[] scannerArray = new Scanner[getColumnCount()];
    try {//from www  . ja v a2 s .co m
        boolean hasNextLine;
        do {

            hasNextLine = false;
            final StringBuilder segmentSB = new StringBuilder();

            for (int colIndex = 0; colIndex < getColumnCount(); colIndex++) {

                final int width = widthCacheArray[colIndex];
                final boolean isFirstColOfRow = colIndex == 0;
                final boolean isLastColOfRow = colIndex == widthCacheArray.length - 1;

                final String borderChar;
                if (isFirstColOfRow && border.has(Border.BORDER_OUTER_LEFT)) {
                    borderChar = "|";
                } else if (!isFirstColOfRow && border.has(Border.BORDER_INNER_V)) {
                    borderChar = "|";
                } else {
                    borderChar = EMPTY;
                }

                if (null == scannerArray[colIndex]) {
                    scannerArray[colIndex] = new Scanner(
                            new StringReader(wrap(getData(rowIndex, columnDefineArray[colIndex]), width)));
                }
                final Scanner scanner = scannerArray[colIndex];

                final String data;
                if (scanner.hasNextLine()) {
                    data = scanner.nextLine();
                    hasNextLine = true;
                } else {
                    data = EMPTY;
                }

                if (width > 0) {
                    final ColumnDefine columnDefine = columnDefineArray[colIndex];
                    final String dataFormat = getDataFormat(columnDefine, width, data);
                    final String paddingChar = repeat(" ", padding);
                    segmentSB.append(format(borderChar + paddingChar + dataFormat + paddingChar, data));
                }

                if (isLastColOfRow) {
                    if (border.has(Border.BORDER_OUTER_RIGHT)) {
                        segmentSB.append("|");
                    }
                    segmentSB.append("\n");
                }

            }

            if (hasNextLine) {
                rowSB.append(segmentSB);
            }

        } while (hasNextLine);

        return rowSB.toString();
    } finally {
        for (Scanner scanner : scannerArray) {
            if (null != scanner) {
                scanner.close();
            }
        }
    }

}

From source file:com.joliciel.talismane.GenericLanguageImplementation.java

public void setLanguagePack(File languagePackFile) {
    ZipInputStream zis = null;//from   w  w  w  .j a v a2 s . com
    try {
        zis = new ZipInputStream(new FileInputStream(languagePackFile));
        ZipEntry ze = null;

        Map<String, String> argMap = new HashMap<String, String>();
        while ((ze = zis.getNextEntry()) != null) {
            String name = ze.getName();
            if (name.indexOf('/') >= 0)
                name = name.substring(name.lastIndexOf('/') + 1);
            if (name.equals("languagePack.properties")) {
                Properties props = new Properties();
                props.load(zis);
                argMap = StringUtils.getArgMap(props);
                break;
            }
        } // next zip entry
        zis.close();

        Map<String, String> reverseMap = new HashMap<String, String>();
        for (String key : argMap.keySet()) {
            String value = argMap.get(key);
            if (value.startsWith("replace:")) {
                value = value.substring("replace:".length());
                if (key.equals("textFilters")) {
                    replaceTextFilters = true;
                } else if (key.equals("tokenFilters")) {
                    replaceTokenFilters = true;
                } else if (key.equals("tokenSequenceFilters")) {
                    replaceTokenSequenceFilters = true;
                }
            }
            if (key.equals("locale")) {
                locale = Locale.forLanguageTag(value);
            } else {
                reverseMap.put(value, key);
            }
        }

        zis = new ZipInputStream(new FileInputStream(languagePackFile));
        ze = null;

        while ((ze = zis.getNextEntry()) != null) {
            String name = ze.getName();
            if (name.indexOf('/') >= 0)
                name = name.substring(name.lastIndexOf('/') + 1);
            String key = reverseMap.get(name);
            if (key != null) {
                if (key.equals("transitionSystem")) {
                    transitionSystem = this.getParserService().getArcEagerTransitionSystem();
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    List<String> dependencyLabels = new ArrayListNoNulls<String>();
                    while (scanner.hasNextLine()) {
                        String dependencyLabel = scanner.nextLine();
                        if (!dependencyLabel.startsWith("#")) {
                            if (dependencyLabel.indexOf('\t') > 0)
                                dependencyLabel = dependencyLabel.substring(0, dependencyLabel.indexOf('\t'));
                            dependencyLabels.add(dependencyLabel);
                        }
                    }
                    transitionSystem.setDependencyLabels(dependencyLabels);
                } else if (key.equals("posTagSet")) {
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    posTagSet = this.getPosTaggerService().getPosTagSet(scanner);
                } else if (key.equals("textFilters")) {
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    textFiltersStr = this.getStringFromScanner(scanner);
                } else if (key.equals("tokenFilters")) {
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    tokenFiltersStr = this.getStringFromScanner(scanner);
                } else if (key.equals("tokenSequenceFilters")) {
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    tokenSequenceFiltersStr = this.getStringFromScanner(scanner);
                } else if (key.equals("posTaggerRules")) {
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    posTaggerRulesStr = this.getStringFromScanner(scanner);
                } else if (key.equals("parserRules")) {
                    Scanner scanner = new Scanner(zis, "UTF-8");
                    parserRulesStr = this.getStringFromScanner(scanner);
                } else if (key.equals("sentenceModel")) {
                    ZipInputStream innerZis = new ZipInputStream(new UnclosableInputStream(zis));
                    sentenceModel = this.getMachineLearningService().getClassificationModel(innerZis);
                } else if (key.equals("tokeniserModel")) {
                    ZipInputStream innerZis = new ZipInputStream(new UnclosableInputStream(zis));
                    tokeniserModel = this.getMachineLearningService().getClassificationModel(innerZis);
                } else if (key.equals("posTaggerModel")) {
                    ZipInputStream innerZis = new ZipInputStream(new UnclosableInputStream(zis));
                    posTaggerModel = this.getMachineLearningService().getClassificationModel(innerZis);
                } else if (key.equals("parserModel")) {
                    ZipInputStream innerZis = new ZipInputStream(new UnclosableInputStream(zis));
                    parserModel = this.getMachineLearningService().getClassificationModel(innerZis);
                } else if (key.equals("lexicon")) {
                    ZipInputStream innerZis = new ZipInputStream(new UnclosableInputStream(zis));
                    LexiconDeserializer deserializer = new LexiconDeserializer(this.getTalismaneSession());
                    lexicons = deserializer.deserializeLexicons(innerZis);
                } else if (key.equals("corpusLexiconEntryRegex")) {
                    Scanner corpusLexicalEntryRegexScanner = new Scanner(zis, "UTF-8");
                    corpusLexicalEntryReader = new RegexLexicalEntryReader(corpusLexicalEntryRegexScanner);
                } else {
                    throw new TalismaneException("Unknown key in languagePack.properties: " + key);
                }
            }
        }
    } catch (FileNotFoundException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    } finally {
        if (zis != null) {
            try {
                zis.close();
            } catch (IOException e) {
                LogUtils.logError(LOG, e);
                throw new RuntimeException(e);
            }
        }
    }
}