Example #1
0
 public Result decode(BinaryBitmap image, Hashtable hints)
     throws NotFoundException, ChecksumException, FormatException {
   DecoderResult decoderResult;
   ResultPoint[] points;
   if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
     BitMatrix bits = extractPureBits(image.getBlackMatrix());
     decoderResult = decoder.decode(bits);
     points = NO_POINTS;
   } else {
     DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
     decoderResult = decoder.decode(detectorResult.getBits());
     points = detectorResult.getPoints();
   }
   Result result =
       new Result(
           decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.DATAMATRIX);
   if (decoderResult.getByteSegments() != null) {
     result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
   }
   if (decoderResult.getECLevel() != null) {
     result.putMetadata(
         ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString());
   }
   return result;
 }
Example #2
0
  protected void checkPrefixCodec(PrefixCodec codec, Random r) throws IOException {
    int[] symbol = new int[100];
    BooleanArrayList bits = new BooleanArrayList();
    for (int i = 0; i < symbol.length; i++) symbol[i] = r.nextInt(codec.size());
    for (int i = 0; i < symbol.length; i++) {
      BitVector word = codec.codeWords()[symbol[i]];
      for (int j = 0; j < word.size(); j++) bits.add(word.get(j));
    }

    BooleanIterator booleanIterator = bits.iterator();
    Decoder decoder = codec.decoder();
    for (int i = 0; i < symbol.length; i++) {
      assertEquals(decoder.decode(booleanIterator), symbol[i]);
    }

    FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
    OutputBitStream obs = new OutputBitStream(fbaos, 0);
    obs.write(bits.iterator());
    obs.flush();
    InputBitStream ibs = new InputBitStream(fbaos.array);

    for (int i = 0; i < symbol.length; i++) {
      assertEquals(decoder.decode(ibs), symbol[i]);
    }
  }
Example #3
0
 public static void main(String... args) {
   try {
     Radiogram r = RadiogramDao.read();
     PrintWriter out = new PrintWriter(System.out);
     out.println(Decoder.decode(r));
     out.flush();
   } catch (IOException e) {
     PrintWriter out = new PrintWriter(System.err);
     out.println("Problems in data access: " + e.getMessage());
     out.flush();
   }
 }
  @Override
  public String lemmatize(LemmaInstance instance) {
    if (cache_ == null) {
      cache_ = new HashMap<>();
    }

    String lemma = cache_.get(instance);
    if (lemma != null) return lemma;

    if (decoder_ == null) {
      decoder_ = options_.getDecoderInstance();
      decoder_.init(model_);
    }

    ToutanovaInstance tinstance = getToutanovaInstance(instance);
    lemma = decoder_.decode(tinstance).getOutput();

    if (lemma == null || lemma.isEmpty()) {
      lemma = "_";
    }

    cache_.put(instance, lemma);
    return lemma;
  }
 @Override
 public Decoded<Source> decode(final Context path, final Target instance) {
   return parent.decode(path, instance);
 }