Evaluate and print precision, recall and F measure.

@throws IOException
if test corpus not loaded
772706
public final void evaluate() throws IOException {
    final ParserEvaluator evaluator = new ParserEvaluator(this.parser);
    evaluator.evaluate(this.testSamples);
    System.out.println(evaluator.getFMeasure());
  }
188926
public static void main(String[] args) throws IOException {
    if (args.length == 0) {
      System.err.println("Usage: PosTaggerME [-td tagdict] model < tokenized_sentences");
      System.err.println("       PosTaggerME -test model \"sentence\"");
      System.exit(1);
    }
    int ai=0;
    boolean test = false;
    String tagdict = null;
    while(ai < args.length && args[ai].startsWith("-")) {
      if (args[ai].equals("-test")) {
        ai++;
        test=true;
      }
      else if (args[ai].equals("-td")) {
        tagdict = args[ai+1];
        ai+=2;
      }
    }
    POSTaggerME tagger;
    String modelFile = args[ai++];
    if (tagdict != null) {
      tagger = new PosTagger(modelFile, new POSDictionary(tagdict));
    }
    else {
      tagger = new PosTagger(modelFile);
    }
    if (test) {
      System.out.println(tagger.tag(args[ai]));
    }
    else {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in,"ISO-8859-1"));
      PrintStream out = new PrintStream(System.out,true,"ISO-8859-1");
      for (String line = in.readLine(); line != null; line = in.readLine()) {
        out.println(tagger.tag(line));
      }
    }
  }
555891
public void print(String s) throws IOException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        { // 306998.15
            Tr.debug(tc, "print --> " + s);
        }
        if (!_hasWritten && obs != null)
        {
            _hasWritten = true;
            obs.alertFirstWrite();
        }
        int len = s.length();
        if (limit > -1)
        {
            if (total + len > limit)
            {
                len = (int)(limit - total);
                except = new WriteBeyondContentLengthException();
            }
        }

        int off = 0;
        while (len > 0)
        {
            int n = buf.length - count;
            if (n == 0)
            {
                response.setFlushMode(false);
                flushChars();
                response.setFlushMode(true);
                n = buf.length - count;
            }
            if (n > len)
            {
                n = len;
            }

            s.getChars(off, off + n, buf, count);

            count += n;
            total += n;
            off += n;
            len -= n;
        }
        check();
    }
1020372
private void readCoordinate() throws IOException {
        for( int i = 0; i < inputDimension; i++ ) {
            if (i <= 1) {
                ordValues[i] = precisionModel.makePrecise(dis.readDouble());
            } else {
                ordValues[i] = dis.readDouble();
            }

        }
    }
1322336
private void checkl() throws DatatypeException, IOException {
        if (context.length() == 0) {
            appendToContext(current);
        }
        current = reader.read();
        appendToContext(current);
        skipSpaces();
        _checkl('l', true);
    }
1264221
def calc_true_performance(self, printout = False):
        
        try:
            self.calc_confusion_matrix(printout = False)
        except DataError as e:
            print(e.msg)
            raise

        if self.TP + self.FP == 0:
            self.precision = np.nan
        else:
            self.precision = self.TP / (self.TP + self.FP)

        if self.TP + self.FN == 0:
            self.recall = np.nan
        else:
            self.recall = self.TP / (self.TP + self.FN)

        if self.precision + self.recall == 0:
            self.F1_measure = np.nan
        else:
            self.F1_measure = ( 2 * self.precision * self.recall /
                                 (self.precision + self.recall) )

        if printout:
            print("True performance is:")
            print("--------------------")
            print("Precision: {} \t Recall: {} \t F1 measure: {}".format(self.precision, self.recall, self.F1_measure))
166318
private void processFilterData() throws IOException
   {
      DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CFilter");
      //FixedMeta fixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedMeta"))), 9);
      //FixedData fixedData = new FixedData(fixedMeta, getEncryptableInputStream(dir, "FixedData"));
      InputStream stream = m_inputStreamFactory.getInstance(dir, "FixedData");
      int blockSize = stream.available() % 115 == 0 ? 115 : 110;
      FixedData fixedData = new FixedData(blockSize, stream, true);
      VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
      Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));

      //System.out.println(fixedMeta);
      //System.out.println(fixedData);
      //System.out.println(varMeta);
      //System.out.println(varData);

      FilterReader reader = new FilterReader9();
      reader.process(m_file.getProjectProperties(), m_file.getFilters(), fixedData, varData);
   }
959058
public final void evaluate() {
    final POSEvaluator evaluator = new POSEvaluator(this.posTagger);
    try {
      evaluator.evaluate(this.testSamples);
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println(evaluator.getWordAccuracy());
  }
751098
private void run() throws IOException
	{
		PrintWriter pw = new PrintWriter(new FileWriter(outputFile));
		LineNumberReader lr = new LineNumberReader(new FileReader(inputFile));
		String line = null;
		int j  = 0;
		//String t = null;
		while ((line = lr.readLine()) != null)
		{
			logger.info(j + " " + line);
			pw.print("1");
			pw.print("\t");
			pw.print(++j);
			pw.print(".tease\t");
			String[] s = line.split(" ");
			for (int i=0;i<s.length - 1;i++)
			{

				String[] t = s[i].split("/");
				if (i != 0)
					pw.print(" ");

				pw.print(i);
				pw.print("&&");
				pw.print(t[0]); // form
				pw.print("&&");
				pw.print(t[1]); // lemma
				pw.print("&&");
				pw.print(t[2]); // pos
				pw.print("&&");
				pw.print(t[3]); // NE  | O
				pw.print("&&");
				pw.print(t[4]); // target | O

			}
			pw.print("\n");
		} // end while
		lr.close();
		pw.flush();
		pw.close();
	}
989195
public void print(final PrintStream out, final ICodingAnnotationStudy study) {
		if (study.getRaterCount() > 2)
			throw new IllegalArgumentException("Contingency tables are only applicable for two rater studies.");
		
		//TODO: measure length of cats. maybe cut them.
		Map<Object, Integer> categories = new LinkedHashMap<Object, Integer>();
		for (Object cat : study.getCategories())
			categories.put(cat, categories.size());
		
		int[][] frequencies = new int[study.getCategoryCount()][study.getCategoryCount()];
		for (ICodingAnnotationItem item : study.getItems()) { 
			int cat1 = categories.get(item.getUnit(0).getCategory());
			int cat2 = categories.get(item.getUnit(1).getCategory());
			frequencies[cat1][cat2]++;
		}
		
		final String DIVIDER = "\t";
		for (Object category : categories.keySet())
			out.print(DIVIDER + category);
		out.print(DIVIDER + "Σ");
		out.println();
		int i = 0;
		int[] colSum = new int[study.getCategoryCount()];
		for (Object category1 : categories.keySet()) {
			out.print(category1);
			int rowSum = 0;
			for (int j = 0; j < categories.size(); j++) {
				out.printf(DIVIDER + "%3d", frequencies[i][j]);
				rowSum += frequencies[i][j];
				colSum[j] += frequencies[i][j];
			}
			out.printf(DIVIDER + "%3d", rowSum);
			out.println();
			i++;
		}
		
		out.print("Σ");
		int rowSum = 0;
		for (int j = 0; j < categories.size(); j++) {
			out.printf(DIVIDER + "%3d", colSum[j]);
			rowSum += colSum[j];
		}
		out.printf(DIVIDER + "%3d", rowSum);
		out.println();
	}
83194
protected void check (File source, String mname, int mline, String fname, int fline)
        throws IOException
    {
        if (mline == -1 && fline != -1) {
            throw new IOException(
                "Found " + fname + " marker (at line " + (fline+1) + ") but no " + mname +
                " marker in '" + source + "'.");
        }
    }
227226
private void processTableData() throws IOException
   {
      DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CTable");

      VarMeta varMeta = new VarMeta12(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
      Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
      FixedData fixedData = new FixedData(230, new DocumentInputStream(((DocumentEntry) dir.getEntry("FixedData"))));
      //System.out.println(varMeta);
      //System.out.println(varData);
      //System.out.println(fixedData);

      TableContainer container = m_file.getTables();
      TableFactory14 factory = new TableFactory14(TABLE_COLUMN_DATA_STANDARD, TABLE_COLUMN_DATA_ENTERPRISE, TABLE_COLUMN_DATA_BASELINE);
      int items = fixedData.getItemCount();
      for (int loop = 0; loop < items; loop++)
      {
         byte[] data = fixedData.getByteArrayValue(loop);
         Table table = factory.createTable(m_file, data, varMeta, varData);
         container.add(table);
         //System.out.println(table);
      }
   }
220008
public void evaluate(final ObjectStream<SequenceLabelSample> samples,
      final int nFolds) throws IOException {

    // Note: The name samples need to be grouped on a document basis.

    final CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<DocumentSample>(
        new NameToDocumentSampleStream(samples), nFolds);

    while (partitioner.hasNext()) {

      final CrossValidationPartitioner.TrainingSampleStream<DocumentSample> trainingSampleStream = partitioner
          .next();

      SequenceLabelerModel model = null;
      if (this.factory != null) {
        model = SequenceLabelerME.train(this.languageCode,
            new DocumentToNameSampleStream(trainingSampleStream), this.params,
            this.factory);
      } else {
        System.err.println("You need to implement a SequenceLabelerFactory!");
        System.exit(1);
      }
      
      String corpusFormat = Flags.getCorpusFormat(this.params);
      // do testing
      final SequenceLabelerEvaluator evaluator = new SequenceLabelerEvaluator(corpusFormat,
          new SequenceLabelerME(model), this.listeners);

      evaluator.evaluate(new DocumentToNameSampleStream(
          trainingSampleStream.getTestSampleStream()));

      this.fmeasure.mergeInto(evaluator.getFMeasure());
    }
  }
39870
protected void printError(final String id, final Span references[],
      final Span predictions[], final T referenceSample,
      final T predictedSample, final String[] sentenceTokens) {
    final List<Span> falseNegatives = new ArrayList<Span>();
    final List<Span> falsePositives = new ArrayList<Span>();

    findErrors(references, predictions, falseNegatives, falsePositives);

    if (falsePositives.size() + falseNegatives.size() > 0) {

      if (id != null) {
        this.printStream.println("Id: {" + id + "}");
      }

      printSamples(referenceSample, predictedSample);

      printErrors(falsePositives, falseNegatives, sentenceTokens);

    }
  }
772350
public void processDocument(BufferedReader document) throws IOException {
        int docIndex = documentCounter.getAndIncrement();

        Iterator<String> documentTokens = 
            IteratorFactory.tokenizeOrdered(document);

        // As we read in the document, generate a compressed version of it,
        // which we will use during the process space method to recompute all of
        // the word vectors' semantics
        ByteArrayOutputStream compressedDocument = 
            new ByteArrayOutputStream(4096);
        DataOutputStream dos = new DataOutputStream(compressedDocument);
        int tokens = 0; // count how many are in this document
        int unfilteredTokens = 0; // how many tokens remained after filtering

        IntegerVector docVector = createVector();
        docToVector.put(docIndex, docVector);

        while (documentTokens.hasNext()) {
            tokens++;
            String focusWord = documentTokens.next();

            // If we are filtering the semantic vectors, check whether this word
            // should have its semantics calculated.  In addition, if there is a
            // filter and it would have excluded the word, do not keep its
            // semantics around
            boolean calculateSemantics =
                semanticFilter.isEmpty() || semanticFilter.contains(focusWord)
                && !focusWord.equals(IteratorFactory.EMPTY_TOKEN);

	    // If the filter does not accept this word, skip the semantic
	    // processing, continue with the next word
            if (!calculateSemantics) {
                // Do not write out any removed tokens to save space
		continue;
	    }

            // Update the occurrences of this token
            unfilteredTokens++;
            add(docVector, getTermIndexVector(focusWord));

            // Update the compress version of the document with the token.
            //
            // NOTE: this call to termToIndex *must* come after the
            // getTermIndexVector() call, which is responsible for adding this
            // mapping if it doesn't already exist.
	    int focusIndex = termToIndex.get(focusWord);

            // write the term index into the compressed for the document for
            // later corpus reprocessing
            dos.writeInt(focusIndex);
        }

        document.close();
        
        dos.close();
        byte[] docAsBytes = compressedDocument.toByteArray();

        // Once the document is finished, write the compressed contents to the
        // corpus stream
        synchronized(compressedDocumentsWriter) {
            // Write how many terms were in this document after filtering
            compressedDocumentsWriter.writeInt(unfilteredTokens);
            compressedDocumentsWriter.write(docAsBytes, 0, docAsBytes.length);
        }
    }
62341
private void processParameters() throws IOException {
        type = JPEG2000;
        originalType = ORIGINAL_JPEG2000;
        inp = null;
        try {
            if (rawData == null){
                inp = url.openStream();
            }
            else{
                inp = new java.io.ByteArrayInputStream(rawData);
            }
            boxLength = cio_read(4);
            if (boxLength == 0x0000000c) {
                boxType = cio_read(4);
                if (JP2_JP != boxType) {
                    throw new IOException("Expected JP Marker");
                }
                if (0x0d0a870a != cio_read(4)) {
                    throw new IOException("Error with JP Marker");
                }

                jp2_read_boxhdr();
                if (JP2_FTYP != boxType) {
                    throw new IOException("Expected FTYP Marker");
                }
                Utilities.skip(inp, boxLength - 8);
                jp2_read_boxhdr();
                do {
                    if (JP2_JP2H != boxType) {
                        if (boxType == JP2_JP2C) {
                            throw new IOException("Expected JP2H Marker");
                        }
                        Utilities.skip(inp, boxLength - 8);
                        jp2_read_boxhdr();
                    }
                } while(JP2_JP2H != boxType);
                jp2_read_boxhdr();
                if (JP2_IHDR != boxType) {
                    throw new IOException("Expected IHDR Marker");
                }
                scaledHeight = cio_read(4);
                setTop(scaledHeight);
                scaledWidth = cio_read(4);
                setRight(scaledWidth);
                bpc = -1;
            }
            else if (boxLength == 0xff4fff51) {
                Utilities.skip(inp, 4);
                int x1 = cio_read(4);
                int y1 = cio_read(4);
                int x0 = cio_read(4);
                int y0 = cio_read(4);
                Utilities.skip(inp, 16);
                colorspace = cio_read(2);
                bpc = 8;
                scaledHeight = y1 - y0;
                setTop(scaledHeight);
                scaledWidth = x1 - x0;
                setRight(scaledWidth);
            }
            else {
                throw new IOException("Not a valid Jpeg2000 file");
            }
        }
        finally {
            if (inp != null) {
                try{inp.close();}catch(Exception e){}
                inp = null;
            }
        }
        plainWidth = getWidth();
        plainHeight = getHeight();
    }
1352546
private void processCharacters(final Characters paramText) throws IOException, XMLStreamException,
        TTException {
        assert paramText != null;
        // Initialize variables.
        initializeVars();
        final String text = paramText.getData().toString();
        if (!text.isEmpty()) {
            // Main algorithm to determine if same, insert or a delete has to be
            // made.
            algorithm(paramText);

            if (mFound && mIsRightSibling) {
                /*
                 * Cannot happen because if text node after end tag get's
                 * deleted it's done already while parsing the end tag. If text
                 * node should be deleted at the top of a subtree (right after a
                 * start tag has been parsed) it's done in
                 * processStartTag(StartElement).
                 */
                // mDelete = EDelete.ATSTARTMIDDLE;
                // deleteNode();
                throw new AssertionError("");
            } else if (!mFound) {
                insertTextNode(paramText);
            } else if (mFound) {
                sameTextNode();
            }
        }
    }