/* TODO: this doesn't work -- if you have multiple streams or processes sharing a json corpus the counts get crazy
       * Also its super annoying so I commented it out...
       * :'(
       */
private void readAnnotations(final Document<D> doc, final String annSet, final String path) {
    final File file = new File(path + File.separator + doc.get(BaseDocument.id) + ".json");
//    log.info("Reading annotations from {}", file.getPath());
    if (!file.exists() || file.length() == 0) {
      /* TODO: this doesn't work -- if you have multiple streams or processes sharing a json corpus the counts get crazy
       * Also its super annoying so I commented it out...
       * :'(
       */
//      noAnnotationsCount++;
//      if (noAnnotationsCount % 100 == 1) {
//        log.debug("{} document(s) do not have {} annotations", noAnnotationsCount, annSet);
//      }
    }
    else {
      try (JsonParser jp = jf.createParser(compression.inputWrapper.apply(Files.newInputStream(file.toPath())))) {
        // until the end of this json object
        while (jp.nextToken() != JsonToken.END_OBJECT) {
          // skip types
          if ("types".equals(jp.getCurrentName())) {
            while (jp.nextToken() != JsonToken.END_OBJECT) {
              ; // do nothing: we just want to increment the parser's position
            }
          }
          JsonToken jt;
          // annotation map
          if ("annotations".equals(jp.getCurrentName())) {
            String type;
            jp.nextToken();
            while ((jt = jp.nextToken()) != JsonToken.END_OBJECT) {
              if (jt == JsonToken.START_OBJECT) {
                type = jp.getCurrentName();
                while(jp.nextToken() != JsonToken.END_OBJECT) {
                  readAnnotation(jp, doc, annSet, type);
                }
              }
            }
          }
          //relation map
          if ("relations".equals(jp.getCurrentName())) {
            String type;
            jp.nextToken();
            while ((jt = jp.nextToken()) != JsonToken.END_OBJECT) {
              if (jt == JsonToken.START_OBJECT) {
                type = jp.getCurrentName();
                while(jp.nextToken() != JsonToken.END_OBJECT) {
                  readRelation(jp, doc, annSet, type);
                }
              }
            }
          }
        }
      } catch (IOException | ClassNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
  }
// log.info("Reading annotations from {}", file.getPath());
if (!file.exists() || file.length() == 0) {
/* TODO: this doesn't work -- if you have multiple streams or processes sharing a json corpus the counts get crazy
* Also its super annoying so I commented it out...
* :'(
*/
// noAnnotationsCount++;
// if (noAnnotationsCount % 100 == 1) {
private void readAnnotations(final Document<D> doc, final String annSet, final String path) {
final File file = new File(path + File.separator + doc.get(BaseDocument.id) + ".json");
// log.info("Reading annotations from {}", file.getPath());
if (!file.exists() || file.length() == 0) {
/* TODO: this doesn't work -- if you have multiple streams or processes sharing a json corpus the counts get crazy
* Also its super annoying so I commented it out...
* :'(
*/
// noAnnotationsCount++;
// if (noAnnotationsCount % 100 == 1) {
// log.debug("{} document(s) do not have {} annotations", noAnnotationsCount, annSet);
// }
}
else {
try (JsonParser jp = jf.createParser(compression.inputWrapper.apply(Files.newInputStream(file.toPath())))) {
// until the end of this json object
while (jp.nextToken() != JsonToken.END_OBJECT) {
// skip types
private void readAnnotations(final Document<D> doc, final String annSet, final String path) {
final File file = new File(path + File.separator + doc.get(BaseDocument.id) + ".json");
// log.info("Reading annotations from {}", file.getPath());
if (!file.exists() || file.length() == 0) {
/* TODO: this doesn't work -- if you have multiple streams or processes sharing a json corpus the counts get crazy
* Also its super annoying so I commented it out...
* :'(
*/
// noAnnotationsCount++;
// if (noAnnotationsCount % 100 == 1) {
// log.debug("{} document(s) do not have {} annotations", noAnnotationsCount, annSet);
// }
}
else {
try (JsonParser jp = jf.createParser(compression.inputWrapper.apply(Files.newInputStream(file.toPath())))) {
// until the end of this json object
while (jp.nextToken() != JsonToken.END_OBJECT) {
// skip types
if ("types".equals(jp.getCurrentName())) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
; // do nothing: we just want to increment the parser's position
}
}
JsonToken jt;
// annotation map
if ("annotations".equals(jp.getCurrentName())) {
String type;
jp.nextToken();