Examples of YKDictionary


Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

  protected void writeExcel(List<YKDocument> documents, File file, CategoryNode node, int winsize) throws Exception {
    final List<YKDocument> docs = documents;
    final File outputFile = file;
    final FileOutputStream stream = new FileOutputStream(outputFile);       
    final CategoryNode catnode = node;
    final YKDictionary dict = yoshikoder.getDictionary();
    final int wsize = winsize;
   
    tworker = new TaskWorker(yoshikoder){
      protected void doWork() throws Exception {
        // TODO remove redundant code here!
       
        // 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)
          counts = getDocumentStats(d.getTitle(), conc, keys, dict.getDictionaryRoot());

          row = sheet.createRow((short)rownum);
          cell = row.createCell((short)0);
          cell.setEncoding(HSSFCell.ENCODING_UTF_16);
          cell.setCellValue(d.getTitle());
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

  protected void writeCsvUTF8(List<YKDocument> documents, File file, CategoryNode node, int winsize) throws Exception {
    final List<YKDocument> docs = documents;
    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),
        Charset.forName("UTF8")));
    final CategoryNode catnode = node;
    final YKDictionary dict = yoshikoder.getDictionary();
    final int wsize = winsize;
   
    tworker = new TaskWorker(yoshikoder){
      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());

          writer.write(FileUtil.escapeForCsv(d.getTitle()));
          for (int ii = 0; ii < keys.length; ii++) {
            writer.write("," + counts[ii]);
          }
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

  }
 
  @Override
  public void actionPerformed(ActionEvent e) {
    Node node = yoshikoder.getSelectedNode();
    YKDictionary dict = yoshikoder.getDictionary();
    CategoryNode cnode = null;
    if (node instanceof CategoryNode)
      cnode = (CategoryNode)node;
    else
      cnode = (CategoryNode)node.getParent();
   
    if (area == null){
      area = new JTextArea(20,30);
      area.setEditable(true);
      area.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
      area.setDropMode(DropMode.INSERT);
      area.setLineWrap(true);
      area.setWrapStyleWord(true);
    } else {
      area.setText("");
    }
   
    JScrollPane pane = new JScrollPane(area);
    int resp = JOptionPane.showConfirmDialog(yoshikoder, pane, "Add patterns to " + cnode.getName(),
      JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (resp != JOptionPane.OK_OPTION)
      return;
   
    String str = area.getText();
    String[] spl = str.split("[^\\w]+");
    List<String> errors = new ArrayList<String>();
    for (int ii = 0; ii < spl.length; ii++) {
      String newpat = spl[ii];
      try {
        dict.addPattern(spl[ii], null, cnode);
      } catch (DuplicateException dex){
        // quietly supress duplicates
      } catch (Exception ex){
        errors.add(spl[ii]);
      }
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

        File f = new File(dictionarySaver.getDirectory(), FileUtil.suffix(fname, "ykd"));
       
        final File file = FileUtil.suffix(f, "ykd");
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                YKDictionary dict = yoshikoder.getDictionary();
                ExportUtil.exportAsXML(dict, file);
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not save dictionary", e);
            }
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

              // tokenize the document
            TokenizationCache tcache = yoshikoder.getTokenizationCache();
            TokenList tl1 = tcache.getTokenList(doc1);
                if (tl1 == null)
                  tl1 = TokenizationService.getTokenizationService().tokenize(doc1);
                 YKDictionary dict = yoshikoder.getDictionary();
               
                 // compute the dictionary counts
                EntryFrequencyMap efm1 = new EntryFrequencyMap(catnode, tl1);
                List lkeys = efm1.getSortedCategoryEntries();
                Node[] keys = (Node[])lkeys.toArray(new Node[lkeys.size()]);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

              // tokenize the document
            TokenizationCache tcache = yoshikoder.getTokenizationCache();
            TokenList tl1 = tcache.getTokenList(doc1);
                if (tl1 == null)
                  tl1 = TokenizationService.getTokenizationService().tokenize(doc1);
                 YKDictionary dict = yoshikoder.getDictionary();
               
                 // compute the dictionary counts
                EntryFrequencyMap efm1 = new EntryFrequencyMap(catnode, tl1);
                List lkeys = efm1.getSortedCategoryEntries();
                Node[] keys = (Node[])lkeys.toArray(new Node[lkeys.size()]);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

    public void dropActionChanged(DragSourceDragEvent dsde) {
    }

    public void dragDropEnd(DragSourceDropEvent dsde) {
        if (dsde.getDropSuccess()) {
            YKDictionary dict = (YKDictionary)sourceTree.getModel();
            dict.remove(oldNode);
           
            // Remove the node only if the drop was successful.
            /*            
             ((DefaultTreeModel)sourceTree.getModel())
                    .removeNodeFromParent(oldNode);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

            l.add(node);
        }
    }
   
    public void actionPerformed(ActionEvent e) {
        YKDictionary dict = yoshikoder.getDictionary();
        Map nameToNodes = new HashMap();
        Node root = dict.getDictionaryRoot();
        recurse(nameToNodes, root); // full nameToNodes
        StringBuffer sb = new StringBuffer();
        int duplicatePatterns = 0;
        for (Iterator iter = nameToNodes.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry)iter.next();
            List l = (List)entry.getValue();
            if (l.size() > 1){
                duplicatePatterns++;
                sb.append("\"" + (String)entry.getKey() + "\" appears in categories:\n");
                for (Iterator iterator = l.iterator(); iterator.hasNext();) {
                    Node node = (Node) iterator.next();
                    TreePath path = dict.getPath((Node)node.getParent());
                    sb.append("\t" + path.getPathComponent(0).toString());
                    for (int ii = 1; ii < path.getPathCount(); ii++) {
                        sb.append(">" + path.getPathComponent(ii).toString()); // path
                    }
                    sb.append("\n");
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

    public ExportDictionaryAsHtml(Yoshikoder yk) {
        super(yk, ExportDictionaryAsHtml.class.getName());
    }
   
    public void actionPerformed(ActionEvent e) {
        final YKDictionary dict = yoshikoder.getDictionary();
       
        if (dictionaryExporter == null)
            dictionaryExporter = DialogUtil.makeFileDialog(yoshikoder,
                "Export Dictionary as HTML", FileDialog.SAVE, null);
       
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.dictionary.YKDictionary

                    // object and add it
                    // to our tree.
                    dtde.acceptDrop(DnDConstants.ACTION_MOVE);
                    TreePath p = (TreePath)tr.getTransferData(flavors[i]);
                    Node node = (Node)p.getLastPathComponent();
                    YKDictionary dict = (YKDictionary)targetTree.getModel();
                    if (node instanceof PatternNode)
                        dict.addPattern((PatternNode)node, (CategoryNode)parent);
                    else if (node instanceof CategoryNode)
                      dict.addCategory((CategoryNode)node, (CategoryNode)parent);   
                    // Last but not least, mark the drop a success.
                    dtde.dropComplete(true);
                    return;
                }
            }
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.