Examples of TokenList


Examples of com.lastcalc.TokenList

        return ParseResult.fail();
      final List<Object> list = (List<Object>) datastructure;
      ret = Lists.newArrayListWithCapacity(list.size() * 4);
      ret.add("[");
      for (final Object o : list) {
        final TokenList result = context.parseEngine.parseAndGetLastStep(
            udp.parse(TokenList.createD(o), 0).output, context);
        if (result.size() != 1 || !(result.get(0) instanceof Boolean))
          return ParseResult.fail();
        if (result.get(0).equals(true)) {
          ret.add(o);
          ret.add(",");
        }
      }
      ret.set(ret.size() - 1, "]"); // Overwrite last comma
View Full Code Here

Examples of com.lastcalc.TokenList

    final boolean condition = (Boolean) tokens.get(templatePos + 1);
    final int end = PreParser.findEdgeOrObjectForwards(tokens, templatePos + 2, null) + 1;
    final int elsePos = PreParser.findEdgeOrObjectForwards(tokens, templatePos + 2, "else");
    if (!tokens.get(elsePos).equals("else"))
      return ParseResult.fail();
    TokenList ret;
    if (condition) {
      ret = new TokenList.SubTokenList(tokens, templatePos + 3, elsePos);
    } else {
      ret = new TokenList.SubTokenList(tokens, elsePos + 1, end);
    }
View Full Code Here

Examples of com.lastcalc.TokenList

            worksheetRequest.questions.put(2,"double 5");
            WorksheetServlet.getWorksheetResponse(worksheet, worksheetRequest, "");
        }


        final TokenList result=worksheet.qaPairs.get(1).answer;


        Assert.assertEquals(1, result.size());

        Assert.assertTrue("Assert that " + result.get(0).getClass() + " is a Number", result.get(0) instanceof org.jscience.mathematics.number.Number);
        double value = ((Number) result.get(0)).doubleValue();
        Assert.assertEquals(10.0, value,0.01);

        System.out.println("worksheet servlet test finished");

    }
View Full Code Here

Examples of com.plainsource.commons.text.template.token.TokenList

    }

    private TokenList createInvoiceLinesHeader() {

        // Invoice line header
        TokenList invoiceLineHeaderTokens = new TokenList("invoiceLineHeaderTokens", new ArrayList<Tokenizer>());
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_DESCRIPTION_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_DESCRIPTION_LABEL.toString(locale)));

        // depending on the configuration, adds the unit code as a field of the invoice line header
        if (ubl4JConfigurationBean.isIncludeQuantityUnitInInvoiceLine()) {
            invoiceLineHeaderTokens.addToken(new Token(
                    TextLabel.INV_ITEM_UNIT_LABEL.toLowerCase(),
                    TextLabel.INV_ITEM_UNIT_LABEL.toString(locale)));
        }

        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_QUANTITY_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_QUANTITY_LABEL.toString(locale)));
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_PRICE_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_PRICE_LABEL.toString(locale)));
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_SUBTOTAL_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_SUBTOTAL_LABEL.toString(locale)));

        // depending on the configuration, adds the vat rate as a field of the invoice line header
        if (ubl4JConfigurationBean.isIncludeVatRateInInvoiceLine()) {
            invoiceLineHeaderTokens.addToken(new Token(
                    TextLabel.INV_ITEM_VAT_RATE_LABEL.toLowerCase(),
                    TextLabel.INV_ITEM_VAT_RATE_LABEL.toString(locale)));
        }

        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_VAT_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_VAT_LABEL.toString(locale)));
        invoiceLineHeaderTokens.addToken(new Token(
                TextLabel.INV_ITEM_TOTAL_LABEL.toLowerCase(),
                TextLabel.INV_ITEM_TOTAL_LABEL.toString(locale)));
        return invoiceLineHeaderTokens;
    }
View Full Code Here

Examples of com.plainsource.commons.text.template.token.TokenList

    private void addInvoiceLinesTokens() {
        template.addToken(createInvoiceLinesHeader());

        // Invoice lines
        TokenList invoiceLineTokens;
        for (InvoiceLineType invoiceLineType : invoiceType.getInvoiceLine()) {
            invoiceLineTokens = new TokenList("invoiceLineTokens", new ArrayList<Tokenizer>());
            if (invoiceLineType.getItem() != null) {
                Iterator<DescriptionType> descriptions = invoiceLineType.getItem().getDescription().iterator();
                StringBuffer sb = new StringBuffer();
                while (descriptions.hasNext()) {
                    sb.append(descriptions.next().getValue());
                }
                invoiceLineTokens.addToken(new Token(
                        TextLabel.INV_ITEM_DESCRIPTION.toLowerCase(), sb.toString()));
            }

            // Item Quantity
            QuantityConverter quantityConverter =
                    convertInvoiceQuantityIfRequired(invoiceLineType.getInvoicedQuantity(),
                            invoiceLineType.getPrice(), locale, ubl4JConfigurationBean);
            if (quantityConverter.getInvoicedQuantityType() != null) {
                NumberWrapper quantity = new NumberWrapper(quantityConverter.getInvoicedQuantityType().getValue());
                quantity.setLocale(locale);

                // Adding the unit code either as a field in the invoice line or as a single token.
                // It is more practical to add the unit code as a single toke when all invoice lines
                // share the same unit code; or when there is only one invoice line
                String unitCode = quantityConverter.getInvoicedQuantityType().getUnitCode();
                if (ubl4JConfigurationBean.isIncludeQuantityUnitInInvoiceLine()) {
                    invoiceLineTokens.addToken(new Token(
                            TextLabel.INV_ITEM_UNIT.toLowerCase(), unitCode));
                } else {
                    template.addToken(new Token(TextLabel.INV_ITEM_UNIT.toLowerCase(), unitCode));
                }
                invoiceLineTokens.addToken(new Token(
                        TextLabel.INV_ITEM_QUANTITY.toLowerCase(), quantity.format()));
            }

            // Item Price
            PriceType price = quantityConverter.getPriceType();
            PriceAmountType priceAmount = null;
            if (price != null) {
                priceAmount = price.getPriceAmount();
                if (priceAmount != null) {
                    invoiceLineTokens.addToken(new Token(
                            TextLabel.INV_ITEM_PRICE.toLowerCase(),
                            new CurrencyDecimal(priceAmount.getValue(), invoiceTypeCurrency, locale).format()));
                }
            }

            BigDecimal lineExtensionAmount = invoiceLineType.getLineExtensionAmount().getValue();
            invoiceLineTokens.addToken(new Token(
                    TextLabel.INV_ITEM_SUBTOTAL.toLowerCase(),
                    new CurrencyDecimal(lineExtensionAmount, invoiceTypeCurrency, locale).format()));

            // Tax rate  (VAT Rate)
            // Adding the VAT rate either as a field in the invoice line or as a single token.
            if (invoiceLineType.getItem().getClassifiedTaxCategory().size() > 0) {
                Token vatRateToken = new Token(TextLabel.INV_ITEM_VAT_RATE.toLowerCase(),
                        getTaxRateAsFormattedNumber(invoiceLineType, locale).format());
                if (ubl4JConfigurationBean.isIncludeVatRateInInvoiceLine()) {
                    invoiceLineTokens.addToken(vatRateToken);
                } else {
                    template.addToken(vatRateToken);
                }
            }

            BigDecimal taxTotal = invoiceLineType.getTaxTotal().get(0).getTaxAmount().getValue();
            invoiceLineTokens.addToken(new Token(TextLabel.INV_ITEM_VAT.toLowerCase(),
                    new CurrencyDecimal(taxTotal, invoiceTypeCurrency, locale).format()));

            BigDecimal total = lineExtensionAmount.add(taxTotal);
            invoiceLineTokens.addToken(new Token(TextLabel.INV_ITEM_TOTAL.toLowerCase(),
                    new CurrencyDecimal(total, invoiceTypeCurrency, locale).format()));
            template.addToken(invoiceLineTokens);
        }
    }
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.document.tokenizer.TokenList

      sb.append(cl.getRightHandSideView());
      sb.append(" ");
    }
    // tokenize and apply dictionary to the 'document'
    YKDocument doc = new YKDocumentImpl(docTitle, sb.toString());
    TokenList tl = TokenizationService.getTokenizationService().tokenize(doc);
    EntryFrequencyMap efm1 = new EntryFrequencyMap(catnode, tl);

    int[] counts = new int[keys.length+1];
    for (int ii=0; ii<keys.length; ii++) {
      Integer cnt = (Integer) efm1.getEntryCount(keys[ii]);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.document.tokenizer.TokenList

       
        // FIRST DOC
        YKDocument doc1 = (YKDocument)docs.get(0);
        // tokenize the document
        TokenizationCache tcache = yoshikoder.getTokenizationCache();
        TokenList tl1 = tcache.getTokenList(doc1);
        if (tl1 == null)
          tl1 = TokenizationService.getTokenizationService().tokenize(doc1);
       
        // for _all_ categories
        EntryFrequencyMap efm1 = new EntryFrequencyMap(dict.getDictionaryRoot(), tl1);
        List lkeys = efm1.getSortedCategoryEntries();
        Node[] keys = (Node[])lkeys.toArray(new Node[lkeys.size()]);
        int[] counts = new int[keys.length+1];
        for (int ii=0; ii<keys.length; ii++) {
          Integer cnt = (Integer) efm1.getEntryCount(keys[ii]);
          counts[ii] = cnt.intValue();
        }
        // add N
        counts[keys.length] = efm1.getTokenTotal();

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFRow row;
        HSSFCell cell;

        HSSFSheet sheet = wb.createSheet("Category frequencies");

        // header
        row = sheet.createRow((short)0);
        for (int c=0; c<keys.length; c++){
          cell = row.createCell((short)(c+1));
          cell.setEncoding(HSSFCell.ENCODING_UTF_16);
          String nodepath = efm1.getEntryPath(keys[c]);
          cell.setCellValue(nodepath);
        }
        cell = row.createCell((short)(keys.length+1));
        cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        cell.setCellValue("Total");

        int rownum = 1;
        for (Iterator iter = docs.iterator(); iter.hasNext();) {
          YKDocument d = (YKDocument) iter.next();
          TokenList tl2 = tcache.getTokenList(d);
          if (tl2 == null)
            tl2 = TokenizationService.getTokenizationService().tokenize(d);
          Concordance conc = dict.getConcordance(tl2, catnode, wsize);
         
          // note _all_categories counted (implicitly around catnode matches)
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.document.tokenizer.TokenList

      protected void doWork() throws Exception {
        // FIRST DOC
        YKDocument doc1 = (YKDocument)docs.get(0);
        // tokenize the document
        TokenizationCache tcache = yoshikoder.getTokenizationCache();
        TokenList tl1 = tcache.getTokenList(doc1);
        if (tl1 == null)
          tl1 = TokenizationService.getTokenizationService().tokenize(doc1);

        // compute the dictionary counts
        EntryFrequencyMap efm1 = new EntryFrequencyMap(dict.getDictionaryRoot(), tl1);
        List lkeys = efm1.getSortedCategoryEntries();
        Node[] keys = (Node[])lkeys.toArray(new Node[lkeys.size()]);
        int[] counts = new int[keys.length+1];
        for (int ii=0; ii<keys.length; ii++) {
          Integer cnt = (Integer) efm1.getEntryCount(keys[ii]);
          counts[ii] = cnt.intValue();
        }
        // add N
        counts[keys.length] = efm1.getTokenTotal();

        for (int ii = 0; ii < keys.length; ii++) {
          String nodepath = efm1.getEntryPath(keys[ii]);

          writer.write(",");
          writer.write(FileUtil.escapeForCsv(nodepath));
        }
        writer.write(",Total\n");

        // and the rest
        for (Iterator iter = docs.iterator(); iter.hasNext();) {
          YKDocument d = (YKDocument) iter.next();
          TokenList tl2 = tcache.getTokenList(d);
          if (tl2 == null)
            tl2 = TokenizationService.getTokenizationService().tokenize(d);
          Concordance conc = dict.getConcordance(tl2, catnode, wsize);
         
          counts = getDocumentStats(d.getTitle(), conc, keys, dict.getDictionaryRoot());
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.document.tokenizer.TokenList

      //Concordance con = new ConcordanceImpl(wsize);
      TokenizationCache tcache = yoshikoder.getTokenizationCache();
      TokenizationService service = TokenizationService.getTokenizationService();
      Map<YKDocument,Concordance> map = new HashMap<YKDocument,Concordance>();
      for (YKDocument doc : docs) {
        TokenList tl = tcache.getTokenList(doc);
        if (tl == null){
          tl = service.tokenize(doc);
          tcache.putTokenList(doc, tl);
        }
        Concordance c = yoshikoder.getDictionary().getConcordance(tl, n, wsize);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.document.tokenizer.TokenList

  protected int[] getDocumentStats(YKDocument doc, Node[] keys, CategoryNode catnode) throws IOException, TokenizationException {
       
    // tokenize the document
    TokenizationCache tcache = yoshikoder.getTokenizationCache();
        TokenList tl1 = tcache.getTokenList(doc);
        if (tl1 == null)
            tl1 = TokenizationService.getTokenizationService().tokenize(doc);
       
        // compute the dictionary counts
        EntryFrequencyMap efm1 = new EntryFrequencyMap(catnode, tl1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.