@Override public Void doInBackground() { int numPackages = WekaPackageManager.numRepositoryPackages(); if (numPackages < 0) { // there was some problem getting the file that holds this // information from the repository server - try to continue // anyway with a max value of 100 for the number of packages // (since all we use this for is setting the upper bound on // the progress bar). numPackages = 100; } m_progress = new javax.swing.ProgressMonitor(PackageManager.this, "Establising cache...", "", 0, numPackages); ProgressPrintStream pps = new ProgressPrintStream(this); m_error = WekaPackageManager.establishCacheIfNeeded(pps); m_cacheEstablished = true; return null; }
private void getAllPackages() { try { getPackagesAndEstablishLookup(); } catch (Exception ex) { // warn the user that we were unable to get the list of packages // from the repository ex.printStackTrace(); System.err.println("A problem has occurred whilst trying to get all " + "package information. Trying a cache refresh..."); WekaPackageManager.refreshCache(System.out); try { // try again getPackagesAndEstablishLookup(); } catch (Exception e) { e.printStackTrace(); } } }
/** * Returns the log file to use. * * @return the log file */ protected File getLogFile() { String filename; File result; filename = m_Properties.getProperty("LogFile", "%w" + File.separator + "weka.log"); filename = filename.replaceAll("%t", Matcher.quoteReplacement(System.getProperty("java.io.tmpdir"))); filename = filename.replaceAll("%h", Matcher.quoteReplacement(System.getProperty("user.home"))); filename = filename.replaceAll("%c", Matcher.quoteReplacement(System.getProperty("user.dir"))); filename = filename.replaceAll("%w", Matcher.quoteReplacement(WekaPackageManager.WEKA_HOME.toString())); if (System.getProperty("%") != null && System.getProperty("%").length() > 0) { filename = filename.replaceAll("%%", Matcher.quoteReplacement(System.getProperty("%"))); } result = new File(filename); return result; }
public static void runSVMRegression() throws Exception { BufferedReader br = null; int numFolds = 10; br = new BufferedReader(new FileReader("rawData.arff")); Instances trainData = new Instances(br); trainData.setClassIndex(trainData.numAttributes() - 1); br.close(); WekaPackageManager.loadPackages(false, true, false); AbstractClassifier classifier = (AbstractClassifier) Class.forName( "weka.classifiers.functions.supportVector").newInstance(); String options = ("-S 3 -V 10 -T 0"); String[] optionsArray = options.split(" "); classifier.setOptions(optionsArray); classifier.buildClassifier(trainData); Evaluation evaluation = new Evaluation(trainData); /*******************CROSS VALIDATION*************************/ evaluation.crossValidateModel(classifier, trainData, numFolds, new Random(1)); /***********************************************************/ evaluateResults(evaluation); }
@Override public Void doInBackground() { m_cacheRefreshInProgress = true; int progressUpper = WekaPackageManager.repoZipArchiveSize(); if (progressUpper == -1) { // revert to legacy approach progressUpper = WekaPackageManager.numRepositoryPackages(); } if (progressUpper < 0) { // there was some problem getting the file that holds this // information from the repository server - try to continue // anyway with a max value of 100 for the number of packages // (since all we use this for is setting the upper bound on // the progress bar). progressUpper = 100; } // number of KBs for the archive is approx 6 x # packages m_progress.setMaximum(progressUpper); m_refreshCacheBut.setEnabled(false); m_installBut.setEnabled(false); m_unofficialBut.setEnabled(false); m_installedBut.setEnabled(false); m_availableBut.setEnabled(false); m_allBut.setEnabled(false); ProgressPrintStream pps = new ProgressPrintStream(this); m_error = WekaPackageManager.refreshCache(pps); getAllPackages(); return null; }
@Override public void done() { m_progress.setValue(m_progress.getMinimum()); if (m_error != null) { displayErrorDialog("There was a problem refreshing the package\n" + "meta data cache. We'll try to use the repository" + "directly.", m_error); m_detailLabel.setText(""); } else { m_detailLabel.setText("Cache refresh completed"); } m_installBut.setEnabled(true && !WekaPackageManager.m_offline); m_unofficialBut.setEnabled(true); m_refreshCacheBut.setEnabled(true && !WekaPackageManager.m_offline); m_installedBut.setEnabled(true); m_availableBut.setEnabled(true); m_allBut.setEnabled(true); m_availablePackages = null; updateTable(); try { m_browserTools.remove(m_newPackagesAvailableL); m_browserTools.revalidate(); } catch (Exception ex) { } m_cacheRefreshInProgress = false; }
@Override public void done() { m_progress.setValue(m_progress.getMinimum()); if (m_errorOccurred) { m_detailLabel.setText("Problem installing - check log."); } else { m_detailLabel.setText("Package installed successfully."); } m_unofficialBut.setEnabled(true); m_refreshCacheBut.setEnabled(true && !WekaPackageManager.m_offline); m_availableBut.setEnabled(true); m_allBut.setEnabled(true); m_installedBut.setEnabled(true); // force refresh of installed and available packages m_installedPackages = null; m_availablePackages = null; // m_installBut.setEnabled(true); m_installing = false; updateTable(); if (m_table.getSelectedRow() >= 0) { // mainly to update the install/uninstall button status // displayPackageInfo(m_table.getSelectedRow()); updateInstallUninstallButtonEnablement(); } }
@Override public void done() { m_progress.setValue(m_progress.getMinimum()); if (m_unsuccessfulInstalls.size() == 0) { // if (m_successfulInstall) { m_detailLabel.setText("Package(s) installed successfully."); } else { StringBuffer failedPackageNames = new StringBuffer(); for (Package p : m_unsuccessfulInstalls) { failedPackageNames.append(p.getName() + "\n"); } displayErrorDialog( "The following package(s) could not be installed\n" + "for some reason (check the log)\n" + failedPackageNames.toString(), ""); m_detailLabel.setText("Install complete."); } m_unofficialBut.setEnabled(true); m_refreshCacheBut.setEnabled(true && !WekaPackageManager.m_offline); m_availableBut.setEnabled(true); m_allBut.setEnabled(true); m_installedBut.setEnabled(true); // force refresh of installed and available packages m_installedPackages = null; m_availablePackages = null; // m_installBut.setEnabled(true); m_installing = false; updateTable(); if (m_table.getSelectedRow() >= 0) { // mainly to update the install/uninstall button status // displayPackageInfo(m_table.getSelectedRow()); updateInstallUninstallButtonEnablement(); } }
@Override public void run() { try { m_homeB.setEnabled(false); m_backB.setEnabled(false); URLConnection conn = null; URL homeURL = new URL(BROWSER_HOME); org.pentaho.packageManagement.PackageManager pm = WekaPackageManager.getUnderlyingPackageManager(); if (pm.setProxyAuthentication(homeURL)) { conn = homeURL.openConnection(pm.getProxy()); } else { conn = homeURL.openConnection(); } // read the html for the home page - all we want to do here is make // sure that the web server is responding, so that we don't tie // up the JEditorPane indefinitely, since there seems to be no // way to set a timeout in JEditorPane conn.setConnectTimeout(10000); // 10 seconds BufferedReader bi = new BufferedReader(new InputStreamReader(conn.getInputStream())); while (bi.readLine() != null) { // } m_infoPane.setPage(BROWSER_HOME); } catch (Exception ex) { // don't make a fuss } finally { m_homeB.setEnabled(true); m_backB.setEnabled(true); } }
private void getPackagesAndEstablishLookup() throws Exception { m_allPackages = WekaPackageManager.getAllPackages(); // now fill the lookup map m_packageLookupInfo = new TreeMap<String, List<Object>>(); // Iterator<Package> i = allP.iterator(); for (Package p : m_allPackages) { // Package p = i.next(); String packageName = p.getName(); String category = ""; if (p.getPackageMetaDataElement("Category") != null) { category = p.getPackageMetaDataElement("Category").toString(); } // check the load status of this package (if installed) String loadStatus = ""; if (p.isInstalled()) { File packageRoot = new File(WekaPackageManager.getPackageHome().toString()); boolean loaded = WekaPackageManager.loadCheck(p, packageRoot); loadStatus = (loaded) ? "Yes" : "No - check log"; } List<Object> versions = WekaPackageManager.getRepositoryPackageVersions(packageName); List<Object> catAndVers = new ArrayList<Object>(); catAndVers.add(category); catAndVers.add(versions); catAndVers.add(loadStatus); m_packageLookupInfo.put(packageName, catAndVers); } }
public static void main(String[] args) { weka.core.logging.Logger.log(weka.core.logging.Logger.Level.INFO, "Logging started"); LookAndFeel.setLookAndFeel(); PackageManager pm = new PackageManager(); if (!WekaPackageManager.m_noPackageMetaDataAvailable) { String offline = ""; if (WekaPackageManager.m_offline) { offline = " (offline)"; } final javax.swing.JFrame jf = new javax.swing.JFrame("Weka Package Manager" + offline); jf.getContentPane().setLayout(new BorderLayout()); jf.getContentPane().add(pm, BorderLayout.CENTER); jf.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { jf.dispose(); System.exit(0); } }); Dimension screenSize = jf.getToolkit().getScreenSize(); int width = screenSize.width * 8 / 10; int height = screenSize.height * 8 / 10; jf.setBounds(width / 8, height / 8, width, height); jf.setVisible(true); pm.setInitialSplitPaneDividerLocation(); } }
@Override public void run() { try { m_homeB.setEnabled(false); m_backB.setEnabled(false); URLConnection conn = null; URL homeURL = new URL(BROWSER_HOME); org.pentaho.packageManagement.PackageManager pm = WekaPackageManager .getUnderlyingPackageManager(); if (pm.setProxyAuthentication(homeURL)) { conn = homeURL.openConnection(pm.getProxy()); } else { conn = homeURL.openConnection(); } // read the html for the home page - all we want to do here is make // sure that the web server is responding, so that we don't tie // up the JEditorPane indefinitely, since there seems to be no // way to set a timeout in JEditorPane conn.setConnectTimeout(10000); // 10 seconds BufferedReader bi = new BufferedReader(new InputStreamReader( conn.getInputStream())); while (bi.readLine() != null) { // } m_infoPane.setPage(BROWSER_HOME); } catch (Exception ex) { // don't make a fuss } finally { m_homeB.setEnabled(true); m_backB.setEnabled(true); } }
private void getPackagesAndEstablishLookup() throws Exception { m_allPackages = WekaPackageManager.getAllPackages(); // now fill the lookup map m_packageLookupInfo = new TreeMap<String, List<Object>>(); // Iterator<Package> i = allP.iterator(); for (Package p : m_allPackages) { // Package p = i.next(); String packageName = p.getName(); String category = ""; if (p.getPackageMetaDataElement("Category") != null) { category = p.getPackageMetaDataElement("Category").toString(); } // check the load status of this package (if installed) String loadStatus = ""; if (p.isInstalled()) { File packageRoot = new File(WekaPackageManager.getPackageHome() .toString()); boolean loaded = WekaPackageManager.loadCheck(p, packageRoot); loadStatus = (loaded) ? "Yes" : "No - check log"; } List<Object> versions = WekaPackageManager .getRepositoryPackageVersions(packageName); List<Object> catAndVers = new ArrayList<Object>(); catAndVers.add(category); catAndVers.add(versions); catAndVers.add(loadStatus); m_packageLookupInfo.put(packageName, catAndVers); } }
@Override public void done() { m_progress.setValue(m_progress.getMinimum()); if (m_error != null) { displayErrorDialog("There was a problem refreshing the package\n" + "meta data cache. We'll try to use the repository" + "directly.", m_error); m_detailLabel.setText(""); } else { m_detailLabel.setText("Cache refresh completed"); } m_installBut.setEnabled(true && !WekaPackageManager.m_offline); m_unofficialBut.setEnabled(true); m_refreshCacheBut.setEnabled(true && !WekaPackageManager.m_offline); m_installedBut.setEnabled(true); m_availableBut.setEnabled(true); m_allBut.setEnabled(true); updateTable(); try { m_browserTools.remove(m_newPackagesAvailableL); m_browserTools.revalidate(); } catch (Exception ex) { } m_cacheRefreshInProgress = false; }
@SuppressWarnings("unchecked") private void loadUserComponents() { Vector<Vector<Object>> tempV = null; // String ext = ""; /* * if (m_UserComponentsInXML) ext = USERCOMPONENTS_XML_EXTENSION; */ File sFile = new File(weka.core.WekaPackageManager.WEKA_HOME.getPath() + File.separator + "knowledgeFlow" + File.separator + "userComponents"); /* * new File(System.getProperty("user.home") +File.separator + * ".knowledgeFlow" +File.separator + "userComponents" +ext); */ if (sFile.exists()) { try { /* * if (m_UserComponentsInXML) { XMLBeans xml = new * XMLBeans(m_beanLayout, m_bcSupport, XMLBeans.DATATYPE_USERCOMPONENTS, * 0); tempV = (Vector) xml.read(sFile); } else { */ InputStream is = new FileInputStream(sFile); ObjectInputStream ois = new ObjectInputStream(is); tempV = (Vector<Vector<Object>>) ois.readObject(); ois.close(); // } } catch (Exception ex) { weka.core.logging.Logger.log(weka.core.logging.Logger.Level.WARNING, "[KnowledgeFlow] Problem reading user components."); ex.printStackTrace(); return; } if (tempV.size() > 0) { DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); if (m_userCompNode == null) { m_userCompNode = new InvisibleNode("User"); model.insertNodeInto(m_userCompNode, root, 0); } // add the components for (int i = 0; i < tempV.size(); i++) { Vector<Object> tempB = tempV.elementAt(i); String displayName = (String) tempB.get(0); tempB.get(1); ImageIcon scaledIcon = (ImageIcon) tempB.get(2); JTreeLeafDetails treeLeaf = new JTreeLeafDetails(displayName, tempB, scaledIcon); DefaultMutableTreeNode newUserComp = new InvisibleNode(treeLeaf); model.insertNodeInto(newUserComp, m_userCompNode, 0); // add to the list of user components m_userComponents.add(tempB); // addToUserToolBar(tempB, false); // addToUserTreeNode(tempB, false); } } } }
@Override public Void doInBackground() { Map<String, String> localPackageNameList = WekaPackageManager.getPackageList(true); if (localPackageNameList == null) { // quietly return and see if we can continue anyway return null; } Map<String, String> repositoryPackageNameList = WekaPackageManager.getPackageList(false); if (repositoryPackageNameList == null) { // quietly return and see if we can continue anyway return null; } if (repositoryPackageNameList.keySet().size() < localPackageNameList .keySet().size()) { // package(s) have disappeared from the repository. // Force a cache refresh... RefreshCache r = new RefreshCache(); r.execute(); return null; } StringBuffer newPackagesBuff = new StringBuffer(); StringBuffer updatedPackagesBuff = new StringBuffer(); for (String s : repositoryPackageNameList.keySet()) { if (!localPackageNameList.containsKey(s)) { newPackagesBuff.append(s + "<br>"); } } for (String localPackage : localPackageNameList.keySet()) { String localVersion = localPackageNameList.get(localPackage); String repoVersion = repositoryPackageNameList.get(localPackage); if (repoVersion == null) { continue; } // a difference here indicates a newer version on the server if (!localVersion.equals(repoVersion)) { updatedPackagesBuff.append(localPackage + " (" + repoVersion + ")<br>"); } } if (newPackagesBuff.length() > 0 || updatedPackagesBuff.length() > 0) { String information = "<html><font size=-2>There are new and/or updated packages available " + "on the server (do a cache refresh for more " + "information):"; if (newPackagesBuff.length() > 0) { information += "<br><br><b>New:</b><br>" + newPackagesBuff.toString(); } if (updatedPackagesBuff.length() > 0) { information += "<br><br><b>Updated:</b><br>" + updatedPackagesBuff.toString() + "<br><br>"; } information += "</font></html>"; m_newPackagesAvailableL.setToolTipText(information); m_browserTools.add(m_newPackagesAvailableL); m_browserTools.revalidate(); } return null; }
private void updateInstallUninstallButtonEnablement() { boolean enableInstall = false; boolean enableUninstall = false; boolean enableToggleLoadStatus = false; m_unofficialBut.setEnabled(true); if (!m_installing) { int[] selectedRows = m_table.getSelectedRows(); // check the package to see whether we should enable the // install button or uninstall button. Once we've determined // that the list contains at least one package to be installed // and uninstalled we don't have to check any further for (int selectedRow : selectedRows) { if (!enableInstall || !enableUninstall) { enableInstall = true; // we should always be able to install an // already installed package String packageName = m_table.getValueAt(selectedRow, getColumnIndex(PACKAGE_COLUMN)) .toString(); try { Package p = WekaPackageManager.getRepositoryPackageInfo(packageName); if (!enableUninstall) { enableUninstall = p.isInstalled(); } if (!enableToggleLoadStatus) { enableToggleLoadStatus = p.isInstalled(); } /* * if (!enableInstall) { enableInstall = !p.isInstalled(); } */ } catch (Exception e1) { // not a repository package - just enable the uninstall button enableUninstall = true; enableInstall = false; } } } } else { m_unofficialBut.setEnabled(false); } // now set the button enablement m_installBut.setEnabled(enableInstall && !WekaPackageManager.m_offline); m_forceBut.setEnabled(enableInstall); m_uninstallBut.setEnabled(enableUninstall); m_toggleLoad.setEnabled(enableToggleLoadStatus); }
private void loadUserComponents() { Vector tempV = null; //String ext = ""; /*if (m_UserComponentsInXML) ext = USERCOMPONENTS_XML_EXTENSION; */ File sFile = new File(weka.core.WekaPackageManager.WEKA_HOME.getPath() + File.separator + "knowledgeFlow" + File.separator + "userComponents"); /* new File(System.getProperty("user.home") +File.separator + ".knowledgeFlow" +File.separator + "userComponents" +ext); */ if (sFile.exists()) { try { /*if (m_UserComponentsInXML) { XMLBeans xml = new XMLBeans(m_beanLayout, m_bcSupport, XMLBeans.DATATYPE_USERCOMPONENTS, 0); tempV = (Vector) xml.read(sFile); } else {*/ InputStream is = new FileInputStream(sFile); ObjectInputStream ois = new ObjectInputStream(is); tempV = (Vector)ois.readObject(); ois.close(); //} } catch (Exception ex) { System.err.println("[KnowledgeFlow] Problem reading user components."); ex.printStackTrace(); return; } if (tempV.size() > 0) { DefaultTreeModel model = (DefaultTreeModel) m_componentTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); if (m_userCompNode == null) { m_userCompNode = new DefaultMutableTreeNode("User"); model.insertNodeInto(m_userCompNode, root, 0); } // add the components for (int i = 0; i < tempV.size(); i++) { Vector tempB = (Vector)tempV.elementAt(i); String displayName = (String)tempB.get(0); StringBuffer serialized = (StringBuffer)tempB.get(1); ImageIcon scaledIcon = (ImageIcon)tempB.get(2); JTreeLeafDetails treeLeaf = new JTreeLeafDetails(displayName, tempB, scaledIcon); DefaultMutableTreeNode newUserComp = new DefaultMutableTreeNode(treeLeaf); model.insertNodeInto(newUserComp, m_userCompNode, 0); // add to the list of user components m_userComponents.add(tempB); //addToUserToolBar(tempB, false); //addToUserTreeNode(tempB, false); } } } }
@Override public Void doInBackground() { Map<String, String> localPackageNameList = WekaPackageManager .getPackageList(true); if (localPackageNameList == null) { // quietly return and see if we can continue anyway return null; } Map<String, String> repositoryPackageNameList = WekaPackageManager .getPackageList(false); if (repositoryPackageNameList == null) { // quietly return and see if we can continue anyway return null; } if (repositoryPackageNameList.keySet().size() < localPackageNameList .keySet().size()) { // package(s) have disappeared from the repository. // Force a cache refresh... RefreshCache r = new RefreshCache(); r.execute(); return null; } StringBuffer newPackagesBuff = new StringBuffer(); StringBuffer updatedPackagesBuff = new StringBuffer(); for (String s : repositoryPackageNameList.keySet()) { if (!localPackageNameList.containsKey(s)) { newPackagesBuff.append(s + "<br>"); } } for (String localPackage : localPackageNameList.keySet()) { String localVersion = localPackageNameList.get(localPackage); String repoVersion = repositoryPackageNameList.get(localPackage); if (repoVersion == null) { continue; } // a difference here indicates a newer version on the server if (!localVersion.equals(repoVersion)) { updatedPackagesBuff.append(localPackage + " (" + repoVersion + ")<br>"); } } if (newPackagesBuff.length() > 0 || updatedPackagesBuff.length() > 0) { String information = "<html><font size=-2>There are new and/or updated packages available " + "on the server (do a cache refresh for more " + "information):"; if (newPackagesBuff.length() > 0) { information += "<br><br><b>New:</b><br>" + newPackagesBuff.toString(); } if (updatedPackagesBuff.length() > 0) { information += "<br><br><b>Updated:</b><br>" + updatedPackagesBuff.toString() + "<br><br>"; } information += "</font></html>"; m_newPackagesAvailableL.setToolTipText(information); m_browserTools.add(m_newPackagesAvailableL); m_browserTools.revalidate(); } return null; }
private void updateInstallUninstallButtonEnablement() { boolean enableInstall = false; boolean enableUninstall = false; m_unofficialBut.setEnabled(true); if (!m_installing) { int[] selectedRows = m_table.getSelectedRows(); // check the package to see whether we should enable the // install button or uninstall button. Once we've determined // that the list contains at least one package to be installed // and uninstalled we don't have to check any further for (int i = 0; i < selectedRows.length; i++) { if (!enableInstall || !enableUninstall) { enableInstall = true; // we should always be able to install an // already installed package String packageName = m_table.getValueAt(selectedRows[i], getColumnIndex(PACKAGE_COLUMN)).toString(); try { Package p = WekaPackageManager .getRepositoryPackageInfo(packageName); if (!enableUninstall) { enableUninstall = p.isInstalled(); } /* * if (!enableInstall) { enableInstall = !p.isInstalled(); } */ } catch (Exception e1) { // not a repository package - just enable the uninstall button enableUninstall = true; enableInstall = false; } } } } else { m_unofficialBut.setEnabled(false); } // now set the button enablement m_installBut.setEnabled(enableInstall); m_forceBut.setEnabled(enableInstall); m_uninstallBut.setEnabled(enableUninstall); }