Examples of TaskWorker


Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

          cnode = (CategoryNode)n;
        else // patternnode
          cnode = (CategoryNode)n.getParent();
        final CategoryNode catnode = cnode;
       
        TaskWorker tworker = new TaskWorker(yoshikoder){
            YKDictionaryReportDialog dia;
          Map<YKDocument,EntryFrequencyMap> efmMap;
           
          protected void doWork() throws Exception {
            EntryFrequencyMap efm = null;
            for (YKDocument doc : concmap.keySet()) {
              TokenList tlist = new TokenListImpl();
              Concordance conc = concmap.get(doc);
              for (Iterator iter = conc.iterator(); iter.hasNext();) {
                ConcordanceLine line = (ConcordanceLine) iter.next();
                for (Iterator iterator = line.getLeftHandSide().iterator(); iterator.hasNext();) {
                  Token token = (Token) iterator.next();
                  tlist.add(token);
                }
                for (Iterator iterator = line.getRightHandSide().iterator(); iterator.hasNext();) {
                  Token token = (Token) iterator.next();
                  tlist.add(token);
                }
              }
              efm = new EntryFrequencyMap(yoshikoder.getDictionary(), tlist);
              efmMap.put(doc, efm);
            }
           
            // FIXME use efmMap in the report, not the most recent one!
           
            YKDocument fake =
                    YKDocumentFactory.createDummyDocument("Concordance", "none", "UTF-8");
                DictionaryFrequencyReport reportcatsonly =
                    new DictionaryFrequencyReport("Concordance Report",
                            catnode.getName() + " applied to current concordance",
                            yoshikoder.getDictionary().getName(),
                            fake, efm, false);
                DictionaryFrequencyReport reportcatsandpats =
                    new DictionaryFrequencyReport("Concordance Report",
                        catnode.getName() + "applied to current concordance",
                            yoshikoder.getDictionary().getName(),
                            fake, efm, true);
                dia = new YKDictionaryReportDialog(yoshikoder, reportcatsonly, reportcatsandpats, onlyShowCats);
            }
            protected void onSuccess() {
              dia.setVisible(true);
              onlyShowCats = !dia.getCurrentReport().getShowPatterns();
            }
           
            protected void onError() {
                if (e instanceof TokenizationException){
                    DialogUtil.yelp(yoshikoder, "Tokenization Error", e);
                } else if (e instanceof IOException){
                    DialogUtil.yelp(yoshikoder, "Input/Ouput Error", e);
                } else {
                    DialogUtil.yelp(yoshikoder, "Error", e);
                }
            }
        };
        tworker.start();
    }
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

  protected void writeCsvUTF8(List<YKDocument> documents, File file) throws Exception {
    final List<YKDocument> docs = documents;
    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),
        Charset.forName("UTF8")));
   
    tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
              pushOutCountsCSVUtf8(docs, writer);
            }
            protected void onError() {
              try {
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

  protected void writeExcel(List<YKDocument> documents, File file) throws Exception {
    final List<YKDocument> docs = documents;
    final File outputFile = file;
    final FileOutputStream stream = new FileOutputStream(outputFile);

    tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
              pushOutCountsExcel(docs, stream);
            }
            protected void onError() {
              try {
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

            log.warning("couldn't decode bytes as system encoding");
        }
        encodings.setSelectedItem(new CharsetWrapper(cs));
        encodings.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                TaskWorker tworker = new TaskWorker(PreviewPanel.this.getTopLevelAncestor()){
                    String ns;
                    protected void doWork() throws Exception {
                        Charset newEnc = ((CharsetWrapper)encodings.getSelectedItem()).charset;
                        ns = new String(bytes, newEnc);
                    }
                    protected void onError() {}
                    protected void onSuccess() {
                        text.setText(ns); // actually *this* is the slow bit...
                        text.setCaretPosition(0);                        
                    }
                };
                tworker.start();
            }});
        setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        JPanel enc = new JPanel(new BorderLayout());
        enc.add(encodings, BorderLayout.CENTER);
        enc.add(new JLabel("Encoding: "), BorderLayout.WEST);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

        String fname = concordanceSaver.getFile();
        if (fname == null) return;
       
        final File file =
            new File(concordanceSaver.getDirectory(), FileUtil.suffix(fname, "ykc"));
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
             
              YKDocument d = concordance.keySet().iterator().next();
                Concordance conc = concordance.get(d);
                int ws = conc.getWindowSize();
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

        String filename = projectExporter.getFile();
        if (filename==null) return;
        File f = new File(projectExporter.getDirectory(), filename);       
       
        final File file = FileUtil.suffix(f, "html", "htm");
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                ExportUtil.exportAsHTML(yoshikoder.getProject(), file);
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not export the project as HTML", e);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

        String fname = documentExporter.getFile();
        if (fname == null) return;
       
        File filed = new File(documentExporter.getDirectory(), fname);
        final File file = FileUtil.suffix( filed, "txt");
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                FileUtil.save(file, doc.getText(), "UTF-8");
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not export the document", e); // TODO loc
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

        String filename = dictionaryExporter.getFile();
        if (filename == null) return;
       
        final File file = new File(dictionaryExporter.getDirectory(),
                FileUtil.suffix(filename, "html", "htm"));
        tworker = new TaskWorker(yoshikoder){
            protected void doWork() throws Exception {
                ExportUtil.exportAsHTML(dict, file);
            }
            protected void onError() {
                DialogUtil.yelp(yoshikoder, "Could not export dictionary as HTML", e);
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

                JOptionPane.PLAIN_MESSAGE);   
        if (i != JOptionPane.OK_OPTION)
            return;
               
        // parse the contents and insert the resulting dictionary
        tworker = new TaskWorker(yoshikoder){
            VBProFileParser parser = new VBProFileParser();
            protected void doWork() throws Exception {
                importedDictionary = parser.parse(f, preview.getSelectedEncoding().name());
                importedDictionary.setName(f.getName());
                if (parser.getErrors().size()>0)
View Full Code Here

Examples of edu.harvard.wcfia.yoshikoder.util.TaskWorker

        chooser.show();
        String fname = chooser.getFile();
        if (fname == null) return;

        final File f = new File(chooser.getDirectory(), fname);
        TaskWorker tworker = new TaskWorker(yoshikoder){
            TM tmd;
            protected void doWork() throws Exception {
                tmd =
                    TokenizationService.getTokenizationService().addTokenizerPlugin(f);
                log.info(tmd.name + "/" + tmd.description + "/" + tmd.classname + "/" + tmd.location);
            }
            protected void onError(){
                if (e instanceof DuplicatePluginException){
                    int resp = DialogUtil.askYesNo(yoshikoder,
                            "Replace existing plugin with this name?",
                            "Replace Tokenizer Plugin");
                    if (resp == JOptionPane.YES_OPTION){
                        // replace on the dispatch thread - not ideal
                        try {
                            TM tm =
                                TokenizationService.getTokenizationService().replaceTokenizerPlugin(tmd,f);
                            listModel.removeElement(tmd);
                            listModel.addElement(tm);
                            list.setSelectedValue(tm, true);
                            return;
                   
                        } catch (PluginException ple){
                            log.log(Level.WARNING, "Failed to replace tokenizer", ple);
                        }
                    } else {
                        // just leave things as they are
                        return;
                    }
                }
                String mess =
                    Messages.getString("TokenizerPluginsPanel.metadataExtractionFailure");
                DialogUtil.yelp(yoshikoder, mess, new PluginException(mess));
            }
            protected void onSuccess() {
                listModel.addElement(tmd);
                list.setSelectedValue(tmd, true);
            }
        };
        tworker.start();
    }
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.