Ejemplo n.º 1
0
 @Override
 protected IStructureRecord query(String value) throws AmbitException {
   OpsinResult result = request.name2structure(value);
   if (result.getStatus().equals(OPSIN_RESULT_STATUS.SUCCESS)) {
     record.clear();
     /*
     String str = NameToInchi.convertResultToInChI(result);
     if (str!=null) {
     	record.setContent(str);
     	record.setFormat(IStructureRecord.MOL_TYPE.INC.toString());
     	return record;
     }
     */
     /*
     String str = result.getSmiles();
     if (str!=null) {
     	record.setContent(null);
     	record.setSmiles(str);
     	return record;
     }
     */
     Element cml = result.getCml();
     if (cml != null) {
       record.setContent(cml.toXML());
       record.setFormat(IStructureRecord.MOL_TYPE.CML.toString());
       return record;
     }
     return null; // success reported,but no meaningful result
   } else return null;
 }
Ejemplo n.º 2
0
 private static Element createResults0(Element element) {
   Element newElement = null;
   String tag = element.getLocalName();
   if (ResultsElement.TAG.equals(tag)) {
     newElement = new ResultsElement();
   } else if (ResultElement.TAG.equals(tag)) {
     newElement = new ResultElement();
   } else {
     LOG.error("Unknown element: " + tag);
   }
   XMLUtil.copyAttributes(element, newElement);
   for (int i = 0; i < element.getChildCount(); i++) {
     Node child = element.getChild(i);
     if (child instanceof Text) {
       child = child.copy();
     } else {
       child = ResultsElement.createResults0((Element) child);
     }
     if (newElement != null && child != null) {
       newElement.appendChild(child);
     }
   }
   LOG.trace("XML :" + newElement.toXML());
   return newElement;
 }
Ejemplo n.º 3
0
  public static void generateXML(RPSBulk rpsBulk, String outputFile, String namespace)
      throws IOException {

    Element enviarLoteRpsEnvio = new Element(ENVIAR_LOTE_RPS_ENVIO, namespace);

    Element loteRps = new Element(LOTE_RPS, namespace);
    loteRps.addAttribute(new Attribute("Id", rpsBulk.getId()));

    Element numeroLote = new Element(NUMERO_LOTE, namespace);
    numeroLote.appendChild(rpsBulk.getNumeroLote());
    loteRps.appendChild(numeroLote);

    Element cnpj = new Element(CNPJ, namespace);
    cnpj.appendChild(rpsBulk.getCnpj());
    loteRps.appendChild(cnpj);

    Element inscricaoMunicipal = new Element(INSCRICAO_MUNICIPAL, namespace);
    inscricaoMunicipal.appendChild(rpsBulk.getInscricaoMunicipal());
    loteRps.appendChild(inscricaoMunicipal);

    Element quantidadeRps = new Element(QUANTIDADE_RPS, namespace);
    quantidadeRps.appendChild(Integer.toString(rpsBulk.getQuantidadeRps()));
    loteRps.appendChild(quantidadeRps);

    Element listaRps = new Element(LISTA_RPS, namespace);

    for (RPS rps : rpsBulk.getListaRps()) {
      Element rpsElement = new Element(RPS, namespace);

      Element infRps = new Element(INF_RPS, namespace);
      infRps.addAttribute(new Attribute("Id", rps.getId()));

      Element identificacaoRps = new Element(IDENTIFICACAO_RPS, namespace);

      Element numero = new Element(NUMERO, namespace);
      numero.appendChild(rps.getNumero());
      identificacaoRps.appendChild(numero);

      Element serie = new Element(SERIE, namespace);
      serie.appendChild(rps.getSerie());
      identificacaoRps.appendChild(serie);

      Element tipo = new Element(TIPO, namespace);
      tipo.appendChild(rps.getTipo());
      identificacaoRps.appendChild(tipo);

      infRps.appendChild(identificacaoRps);

      Element dataEmissao = new Element(DATA_EMISSAO, namespace);
      dataEmissao.appendChild(rps.getDataEmissao());
      infRps.appendChild(dataEmissao);

      Element naturezaOperacao = new Element(NATUREZAO_OPERACAO, namespace);
      naturezaOperacao.appendChild(rps.getNaturezaOperacao());
      infRps.appendChild(naturezaOperacao);

      Element optanteSimplesNacional = new Element(OPTANTE_SIMPLES_NACIONAL, namespace);
      optanteSimplesNacional.appendChild(rps.getOptanteSimplesNacional());
      infRps.appendChild(optanteSimplesNacional);

      Element incentivadorCultural = new Element(INCENTIVADOR_CULTURAL, namespace);
      incentivadorCultural.appendChild(rps.getIncentivadorCultural());
      infRps.appendChild(incentivadorCultural);

      Element status = new Element(STATUS, namespace);
      status.appendChild(rps.getStatus());
      infRps.appendChild(status);

      Element servico = new Element(SERVICO, namespace);

      Element valores = new Element(VALORES, namespace);

      Element valorServicos = new Element(VALOR_SERVICOS, namespace);
      valorServicos.appendChild(rps.getValorServicos());
      valores.appendChild(valorServicos);

      Element valorDeducoes = new Element(VALOR_DEDUCOES, namespace);
      valorDeducoes.appendChild(rps.getValorDeducoes());
      valores.appendChild(valorDeducoes);

      Element valorPis = new Element(VALOR_PIS, namespace);
      valorPis.appendChild(rps.getValorPis());
      valores.appendChild(valorPis);

      Element valorCofins = new Element(VALOR_COFINS, namespace);
      valorCofins.appendChild(rps.getValorCofins());
      valores.appendChild(valorCofins);

      Element valorInss = new Element(VALOR_INSS, namespace);
      valorInss.appendChild(rps.getValorInss());
      valores.appendChild(valorInss);

      Element valorIr = new Element(VALOR_IR, namespace);
      valorIr.appendChild(rps.getValorIr());
      valores.appendChild(valorIr);

      Element valorCsll = new Element(VALOR_CSLL, namespace);
      valorCsll.appendChild(rps.valorCsll);
      valores.appendChild(valorCsll);

      Element issRetido = new Element(ISS_RETIDO, namespace);
      issRetido.appendChild(rps.getIssRetido());
      valores.appendChild(issRetido);

      Element valorIss = new Element(VALOR_ISS, namespace);
      valorIss.appendChild(rps.getValorIss());
      valores.appendChild(valorIss);

      Element outrasRetencoes = new Element(OUTRAS_RETENCOES, namespace);
      outrasRetencoes.appendChild(rps.getOutrasRetencoes());
      valores.appendChild(outrasRetencoes);

      Element aliquota = new Element(ALIQUOTA, namespace);
      aliquota.appendChild(rps.getAliquota());
      valores.appendChild(aliquota);

      Element descontoIncondicionado = new Element(DESCONTO_INCONDICIONADO, namespace);
      descontoIncondicionado.appendChild(rps.getDescontoIncondicionado());
      valores.appendChild(descontoIncondicionado);

      Element descontoCondicionado = new Element(DESCONTO_CONDICIONADO, namespace);
      descontoCondicionado.appendChild(rps.getDescontoCondicionado());
      valores.appendChild(descontoCondicionado);

      servico.appendChild(valores);

      Element itemListaServico = new Element(ITEM_LISTA_SERVICO, namespace);
      itemListaServico.appendChild(rps.getItemListaServico());
      servico.appendChild(itemListaServico);

      Element codigoTributacaoMunicipio = new Element(CODIGO_TRIBUTACAO_MUNICIPIO, namespace);
      codigoTributacaoMunicipio.appendChild(rps.getCodigoTributacaoMunicipio());
      servico.appendChild(codigoTributacaoMunicipio);

      Element discriminacao = new Element(DISCRIMINACAO, namespace);
      discriminacao.appendChild(rps.getDiscriminacao());
      servico.appendChild(discriminacao);

      Element servicosCodigoMunicipio = new Element(CODIGO_MUNICIPIO, namespace);
      servicosCodigoMunicipio.appendChild(rps.getServicos_codigoMunicipio());
      servico.appendChild(servicosCodigoMunicipio);

      infRps.appendChild(servico);

      Element prestador = new Element(PRESTADOR, namespace);

      Element prestadorCnpj = new Element(CNPJ, namespace);
      prestadorCnpj.appendChild(rps.getPrestador_cnpj());
      prestador.appendChild(prestadorCnpj);

      Element prestadorInscricaoMunicipal = new Element(INSCRICAO_MUNICIPAL, namespace);
      prestadorInscricaoMunicipal.appendChild(rps.getInscricaoMunicipal());
      prestador.appendChild(prestadorInscricaoMunicipal);

      infRps.appendChild(prestador);

      Element tomador = new Element(TOMADOR, namespace);

      Element identificaoTomador = new Element(IDENTIFICACAO_TOMADOR, namespace);

      Element cpfCnpj = new Element(CPF_CNPJ, namespace);

      if (rps.getTomador_cpf() == null) {
        Element tomadorCnpj = new Element(CNPJ, namespace);
        tomadorCnpj.appendChild(rps.getTomador_cnpj());
        cpfCnpj.appendChild(tomadorCnpj);
      } else {
        Element tomadorCpf = new Element(CPF, namespace);
        tomadorCpf.appendChild(rps.getTomador_cpf());
        cpfCnpj.appendChild(tomadorCpf);
      }
      identificaoTomador.appendChild(cpfCnpj);

      tomador.appendChild(identificaoTomador);

      Element razaoSocial = new Element(RAZAO_SOCIAL, namespace);
      razaoSocial.appendChild(rps.getRazaoSocial());
      tomador.appendChild(razaoSocial);

      Element endereco = new Element(ENDERECO, namespace);

      if (!rps.getEndereco().isEmpty()) {
        Element enderecoEndereco = new Element(ENDERECO, namespace);
        enderecoEndereco.appendChild(rps.getEndereco());
        endereco.appendChild(enderecoEndereco);
      }

      if (!rps.getEndereco_numero().isEmpty()) {
        Element enderecoNumero = new Element(NUMERO, namespace);
        enderecoNumero.appendChild(rps.getEndereco_numero());
        endereco.appendChild(enderecoNumero);
      }

      if (!rps.getComplemento().isEmpty()) {
        Element complemento = new Element(COMPLEMENTO, namespace);
        complemento.appendChild(rps.getComplemento());
        endereco.appendChild(complemento);
      }

      if (!rps.getBairro().isEmpty()) {
        Element bairro = new Element(BAIRRO, namespace);
        bairro.appendChild(rps.getBairro());
        endereco.appendChild(bairro);
      }

      if (!rps.getEndereco_codigoMunicipio().isEmpty()) {
        Element enderecoCodigoMunicipio = new Element(CODIGO_MUNICIPIO, namespace);
        enderecoCodigoMunicipio.appendChild(rps.getEndereco_codigoMunicipio());
        endereco.appendChild(enderecoCodigoMunicipio);
      }

      if (!rps.getUf().isEmpty()) {
        Element uf = new Element(UF, namespace);
        uf.appendChild(rps.getUf());
        endereco.appendChild(uf);
      }

      if (!rps.getCep().isEmpty()) {
        Element cep = new Element(CEP, namespace);
        cep.appendChild(rps.getCep());
        endereco.appendChild(cep);
      }

      if (endereco.getChildElements().size() != 0) {
        tomador.appendChild(endereco);
      }

      Element contato = new Element(CONTATO, namespace);

      Element email = new Element(EMAIL, namespace);
      email.appendChild(rps.getEmail());
      contato.appendChild(email);

      tomador.appendChild(contato);

      infRps.appendChild(tomador);

      rpsElement.appendChild(infRps);
      listaRps.appendChild(rpsElement);
    }
    loteRps.appendChild(listaRps);
    enviarLoteRpsEnvio.appendChild(loteRps);

    // Document doc = new Document(enviarLoteRpsEnvio);

    // Writes to XML console.
    /*	Serializer serializer = new Serializer(System.out, OUTPUT_ENCODING);
    serializer.setIndent(2);
    serializer.setMaxLength(0);
    serializer.write(doc);*/

    // Writes XML to file.
    FileOutputStream fos = new FileOutputStream(outputFile, false);
    PrintWriter pw = new PrintWriter(fos);
    pw.write(enviarLoteRpsEnvio.toXML());
    pw.close();
    fos.close();
  }
Ejemplo n.º 4
0
 public String toXml() {
   return fileTree.toXML();
 }
Ejemplo n.º 5
0
 @Override
 public int hashCode() {
   return fileTree.toXML().hashCode();
 }
Ejemplo n.º 6
0
  public void annotate(CoreMap document) throws IOException {
    // write input file in GUTime format
    Element inputXML = toInputXML(document);
    File inputFile = File.createTempFile("gutime", ".input");

    // Document doc = new Document(inputXML);
    PrintWriter inputWriter = new PrintWriter(inputFile);
    inputWriter.println(inputXML.toXML());
    // new XMLOutputter().output(inputXML, inputWriter);
    inputWriter.close();

    boolean useFirstDate =
        (!document.has(CoreAnnotations.CalendarAnnotation.class)
            && !document.has(CoreAnnotations.DocDateAnnotation.class));

    ArrayList<String> args = new ArrayList<String>();
    args.add("perl");
    args.add("-I" + this.gutimePath.getPath());
    args.add(new File(this.gutimePath, "TimeTag.pl").getPath());
    if (useFirstDate) args.add("-FDNW");
    args.add(inputFile.getPath());
    // run GUTime on the input file
    ProcessBuilder process = new ProcessBuilder(args);

    StringWriter outputWriter = new StringWriter();
    SystemUtils.run(process, outputWriter, null);
    String output = outputWriter.getBuffer().toString();
    Pattern docClose = Pattern.compile("</DOC>.*", Pattern.DOTALL);
    output = docClose.matcher(output).replaceAll("</DOC>");

    // parse the GUTime output
    Element outputXML;
    try {
      Document newNodeDocument = new Builder().build(output, "");
      outputXML = newNodeDocument.getRootElement();
    } catch (ParsingException ex) {
      throw new RuntimeException(
          String.format(
              "error:\n%s\ninput:\n%s\noutput:\n%s", ex, IOUtils.slurpFile(inputFile), output));
    }
    /*
    try {
      outputXML = new SAXBuilder().build(new StringReader(output)).getRootElement();
    } catch (JDOMException e) {
      throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s",
      		e, IOUtils.slurpFile(inputFile), output));
    } */
    inputFile.delete();

    // get Timex annotations
    List<CoreMap> timexAnns = toTimexCoreMaps(outputXML, document);
    document.set(TimexAnnotations.class, timexAnns);
    if (outputResults) {
      System.out.println(timexAnns);
    }

    // align Timex annotations to sentences
    int timexIndex = 0;
    for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
      int sentBegin = beginOffset(sentence);
      int sentEnd = endOffset(sentence);

      // skip times before the sentence
      while (timexIndex < timexAnns.size() && beginOffset(timexAnns.get(timexIndex)) < sentBegin) {
        ++timexIndex;
      }

      // determine times within the sentence
      int sublistBegin = timexIndex;
      int sublistEnd = timexIndex;
      while (timexIndex < timexAnns.size()
          && sentBegin <= beginOffset(timexAnns.get(timexIndex))
          && endOffset(timexAnns.get(timexIndex)) <= sentEnd) {
        ++sublistEnd;
        ++timexIndex;
      }

      // set the sentence timexes
      sentence.set(TimexAnnotations.class, timexAnns.subList(sublistBegin, sublistEnd));
    }
  }