예제 #1
0
 private void writeModel(String filename, OntModel model, NIFParameters nifParameters) {
   try {
     BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
     model.write(writer, Format.toJena(nifParameters.getOutputFormat()));
     writer.close();
   } catch (FileNotFoundException fnf) {
     log.error("Could not find file: " + filename);
   } catch (IOException ioe) {
     log.error("Could not write file: " + filename);
   }
 }
예제 #2
0
  public void transform(OntModel inputModel, OntModel outputModel, NIFParameters nifParameters) {
    this.prefix = nifParameters.getPrefix();

    String uri = this.prefix + "char=0,";
    // only supporting RFC5147 string atm
    contextResource =
        outputModel.createIndividual(
            uri, outputModel.createClass(NIFOntClasses.RFC5147String.getUri()));
    contextResource.addOntClass(NIFOntClasses.Context.getOntClass(outputModel));
    contextResource.addOntClass(NIFOntClasses.String.getOntClass(outputModel));
    contextResource.addProperty(
        NIFDatatypeProperties.beginIndex.getDatatypeProperty(outputModel), "0");

    if (!nifParameters.getOptions().has("informat")) {
      log.warn("informat parameter empty, please choose informat=file or informat=text");
    }

    if (!nifParameters.getOptions().has("tagset")) {
      log.warn(
          "No tagset chosen, please choose an OLiA tagset from: https://github.com/NLP2RDF/software/blob/master/java-maven/vocabularymodule/OLiA/src/main/java/org/nlp2rdf/vm/olia/models");
    } else {
      loadTagset(nifParameters.getOptions().valueOf("tagset").toString());
    }

    if (nifParameters.getOptions().valueOf("intype").equals("file")) {
      if (nifParameters.getOptions().valueOf("informat").equals("text")) {
        File input = new File(nifParameters.getOptions().valueOf("i").toString());
        FileReader reader = null;
        try {
          reader = new FileReader(input);
          this.transformConLL(reader, inputModel, outputModel, nifParameters);
          reader.close();
        } catch (FileNotFoundException fnf) {
          log.error("Could not open file " + nifParameters.getOptions().valueOf("i").toString());
        } catch (IOException e) {
          log.error("Could not read file " + nifParameters.getOptions().valueOf("i").toString());
        }
      }
    } else if (nifParameters.getOptions().valueOf("intype").equals("url")) {
      log.error("URL input not yet supported");
    } else {
      if (nifParameters.getOptions().valueOf("informat").equals("text")) {
        StringReader reader = new StringReader(nifParameters.getOptions().valueOf("i").toString());
        this.transformConLL(reader, inputModel, outputModel, nifParameters);
        reader.close();
      }
    }
  }