Ignore:
Timestamp:
2015-08-03T20:15:28+02:00 (9 years ago)
Author:
nkaragiannakis
Message:

allow custom SVM models

Location:
applications/editors/josm/plugins/OSMRecPlugin
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/OSMRecPlugin/nbproject/private/private.xml

    r31402 r31441  
    44    <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
    55        <group>
     6            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java</file>
     7            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/build.xml</file>
     8            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java</file>
     9            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Mapper.java</file>
     10            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Ontology.java</file>
    611            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPlugin.java</file>
     12            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecToggleDialog.java</file>
    713            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/MenuExportAction.java</file>
     14            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/resources/log4j.properties</file>
     15            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java</file>
     16            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java</file>
     17            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java</file>
     18            <file>file:/home/imis-nkarag/software/josm_svn/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/SampleModelsExtractor.java</file>
    819        </group>
    920    </open-files>
  • applications/editors/josm/plugins/OSMRecPlugin/nbproject/project.xml

    r31402 r31441  
    8181            <compilation-unit>
    8282                <package-root>src</package-root>
    83                 <classpath mode="compile">../../core/dist/josm-custom.jar:lib/liblinear-java-1.95.jar:lib/jena-core-2.12.0.jar:lib/gt-api-9.3.jar:lib/gt-referencing-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-metadata-9.3.jar:lib/slf4j-api-1.7.6.jar:lib/xercesImpl-2.11.0.jar:lib/commons-lang3-3.3.2.jar:lib/commons-pool-1.5.4.jar:lib/gt-api-9.3.jar:lib/gt-metadata-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-referencing-9.3.jar:lib/jai_core-1.1.3.jar:lib/jena-core-2.12.0.jar:lib/jena-iri-1.1.0.jar:lib/jgridshift-1.0.jar:lib/jsonic-1.2.7.jar:lib/jsr-275-1.0-beta-2.jar:lib/langdetect-1.1-20120112.jar:lib/liblinear-1.95.jar:lib/liblinear-java-1.95.jar:lib/lucene-analyzers-3.6.0.jar:lib/lucene-core-3.6.0.jar:lib/slf4j-api-1.7.6.jar:lib/slf4j-log4j12-1.7.6.jar:lib/vecmath-1.3.2.jar:lib/xercesImpl-2.11.0.jar:lib/xml-apis-1.4.01.jar:lib/jts-1.13.jar</classpath>
     83                <classpath mode="compile">../../core/dist/josm-custom.jar:lib/liblinear-java-1.95.jar:lib/jena-core-2.12.0.jar:lib/gt-api-9.3.jar:lib/gt-referencing-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-metadata-9.3.jar:lib/slf4j-api-1.7.6.jar:lib/xercesImpl-2.11.0.jar:lib/commons-lang3-3.3.2.jar:lib/commons-pool-1.5.4.jar:lib/gt-api-9.3.jar:lib/gt-metadata-9.3.jar:lib/gt-opengis-9.3.jar:lib/gt-referencing-9.3.jar:lib/jai_core-1.1.3.jar:lib/jena-core-2.12.0.jar:lib/jena-iri-1.1.0.jar:lib/jgridshift-1.0.jar:lib/jsonic-1.2.7.jar:lib/jsr-275-1.0-beta-2.jar:lib/langdetect-1.1-20120112.jar:lib/liblinear-1.95.jar:lib/liblinear-java-1.95.jar:lib/lucene-analyzers-3.6.0.jar:lib/lucene-core-3.6.0.jar:lib/slf4j-api-1.7.6.jar:lib/slf4j-log4j12-1.7.6.jar:lib/vecmath-1.3.2.jar:lib/xercesImpl-2.11.0.jar:lib/xml-apis-1.4.01.jar:lib/jts-1.13.jar:lib/log4j-1.2.17.jar</classpath>
    8484                <built-to>../../dist</built-to>
    8585                <source-level>1.7</source-level>
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/core/TrainWorker.java

    r31106 r31441  
    3030import java.util.logging.Logger;
    3131import javax.swing.SwingWorker;
    32 import org.opengis.referencing.FactoryException;
    3332import org.openstreetmap.josm.plugins.container.OSMRelation;
    3433import org.openstreetmap.josm.plugins.container.OSMWay;
     
    7877    private static double foldScore10 = 0;
    7978    private static double bestScore = 0;
    80     int trainProgress = 0;
     79    private int trainProgress = 0;
    8180    private final boolean validateFlag;
    8281    private final double cParameterFromUser;
     
    8786    private String textualListFilePath;
    8887   
    89     private static boolean USE_CLASS_FEATURES = false;
    90     private static boolean USE_RELATION_FEATURES = false;
    91     private static boolean USE_TEXTUAL_FEATURES = true;
     88    private static final boolean USE_CLASS_FEATURES = false;
     89    private static final boolean USE_RELATION_FEATURES = false;
     90    private static final boolean USE_TEXTUAL_FEATURES = true;
    9291    private static int numberOfFeatures;
    9392    private static LanguageDetector languageDetector;
     
    173172        if(topKIsSelected){
    174173            textualList = anal.getTopKMostFrequent(topK);
    175             System.out.println(textualList);
     174            //System.out.println(textualList);
    176175        }
    177176        else{
    178177            textualList = anal.getWithFrequency(frequency);
    179             System.out.println(textualList);
     178            //System.out.println(textualList);
    180179        }
    181180
     
    230229        readTextualFromDefaultList(textualFileStream);
    231230     
    232         OSMParser osmParser = null;
    233         try {
    234             osmParser = new OSMParser(inputFilePath);
    235            
    236         } catch (FactoryException ex) {
    237             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    238         }       
     231        OSMParser osmParser = new OSMParser(inputFilePath);     
    239232       
    240233        osmParser.parseDocument();
     
    354347
    355348            if(way.getClassIDs().isEmpty()){
    356                 wayListSizeWithoutUnclassified = wayListSizeWithoutUnclassified-1;
     349                wayListSizeWithoutUnclassified -= 1;
    357350                u++;
    358351            }
     
    465458            //System.out.println("file created");
    466459            model.save(modelFile);
    467             //System.out.println("saved");
     460            System.out.println("model saved at: " + modelFile);
    468461        } catch (IOException ex) {
    469462            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     
    504497            if(way.getClassIDs().isEmpty()){
    505498                //System.out.println("found unclassified" + way.getClassIDs() + "class: " +way.getClassID());
    506                 wayListSizeWithoutUnclassified2 = wayListSizeWithoutUnclassified2-1;
     499                wayListSizeWithoutUnclassified2 -= 1;
    507500                //u++;
    508501            }
     
    614607       
    615608        System.out.println("Succeeded " + succededInstances + " of " + testList.size() + " total (1 class prediction)");
    616         double precision1 = (double)succededInstances/(double)wayListSizeWithoutUnclassified2;
     609        double precision1 = succededInstances/(double)wayListSizeWithoutUnclassified2;
    617610        score1 = precision1;
    618611        System.out.println(precision1);
    619612       
    620613        System.out.println("Succeeded " + succededInstances5 + " of " + testList.size()+ " total (5 class prediction)");
    621         double precision5 = (double)succededInstances5/(double)wayListSizeWithoutUnclassified2;
     614        double precision5 = succededInstances5/(double)wayListSizeWithoutUnclassified2;
    622615        score5 = precision5;
    623616        System.out.println(precision5);
    624617       
    625618        System.out.println("Succeeded " + succededInstances10 + " of " + testList.size()+ " total (10 class prediction)");
    626         double precision10 = (double)succededInstances10/(double)wayListSizeWithoutUnclassified2;
     619        double precision10 = succededInstances10/(double)wayListSizeWithoutUnclassified2;
    627620        score10 = precision10;
    628621        System.out.println(precision10);               
     
    651644
    652645            if(way.getClassIDs().isEmpty()){
    653                 wayListSizeWithoutUnclassified = wayListSizeWithoutUnclassified-1;
     646                wayListSizeWithoutUnclassified -= 1;
    654647                u++;
    655648            }
     
    781774
    782775            if(way.getClassIDs().isEmpty()){
    783                 wayListSizeWithoutUnclassified = wayListSizeWithoutUnclassified-1;
     776                wayListSizeWithoutUnclassified -= 1;
    784777                u++;
    785778            }
     
    888881            //System.out.println("file created");
    889882            model.save(modelFile);
    890             //System.out.println("saved");
     883            System.out.println("model saved at: " + modelFile);
    891884        } catch (IOException ex) {
    892885            Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     
    932925                writer.write(entry.getKey());
    933926                writer.newLine();
    934                 System.out.println(entry.getKey());
     927                //System.out.println(entry.getKey());
    935928            }
    936929        } catch (UnsupportedEncodingException ex) {
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java

    r31402 r31441  
    164164    private static LanguageDetector languageDetector;
    165165    private static String bestModelPath;
     166    private boolean modelWithClasses;// = false;
    166167    private final String modelWithClassesPath;
     168    private boolean useCustomSVMModel = false;
     169    private String customSVMModelPath;
    167170   
    168171   
     
    468471            daysField = new javax.swing.JTextField();
    469472           
     473            cParameterCheckBox.setSelected(true);
    470474            userHistoryPanel.setEnabled(false);
    471475            byAreaRadioButton.setEnabled(false);
     
    490494            inputFileErrorMessageLabel.setForeground(Color.RED);
    491495            inputFileErrorMessageLabel.setText("");
     496            topKField.setText("50");
     497            frequencyField.setText("200");
     498            cParameterField.setText("0.01");
    492499           
    493500            cParameterField.setColumns(FIELD_COLUMNS);
     
    926933            acceptConfigButton.setEnabled(true);         
    927934            fileBrowseButton.setEnabled(true);
     935            trainFromUserCheckBox.setEnabled(true);
    928936           
    929937            if(trainFromUserCheckBox.isSelected()){
     
    967975
    968976                        try {
     977                            System.out.println("executing userDataExtractAndTrainWorker Thread..");
    969978                            userDataExtractAndTrainWorker.execute();
    970979                        } catch (Exception ex) {
     
    11971206        private final JButton chooseModelButton;
    11981207        private final JTextField chooseModelTextField;
    1199         private final JList modelCombinationList;
    1200         private final DefaultListModel<String> combinationDefaultListModel = new DefaultListModel<>();;
     1208        private final JList<String> modelCombinationList;
     1209        private final DefaultListModel<String> combinationDefaultListModel = new DefaultListModel<>();
    12011210        private final JPanel modelCombinationPanel;
    12021211        //private final JTextField weightTextField;
     
    13361345                System.out.println("\n\nUSE COMBINED MODEL\n\n");
    13371346                //recompute predictions with combination
    1338                 addDialog.loadSVMmodel(false); //maybe ask user about if the model contains classes               
     1347                modelWithClasses = false;
     1348                addDialog.loadSVMmodel();
     1349                addDialog.createOSMObject(sel);
    13391350            }
    13401351            else {
    13411352                useCombinedModel = false;
     1353                addDialog.loadSVMmodel();
     1354                addDialog.createOSMObject(sel);
    13421355            }           
    13431356        }
     
    13511364                if(returnVal == JFileChooser.APPROVE_OPTION) {
    13521365                    chooseModelTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
    1353                 }
     1366                    useCustomSVMModel = true;
     1367                    customSVMModelPath = fileChooser.getSelectedFile().getAbsolutePath();
     1368                }
     1369               
    13541370               
    13551371                if(useModelCombinationCheckbox.isSelected()){
     
    13911407                    weightPanelComponent.setEnabled(true);
    13921408                }
    1393                
     1409                useCustomSVMModel = false; //reseting the selected custom SVM model only here
    13941410            }
    13951411            else{
     
    14161432
    14171433                    weightValue = Math.abs(weightValue);
    1418                     weightSum = weightSum + weightValue;
     1434                    weightSum += weightValue;
    14191435                }   
    14201436                catch (NumberFormatException ex){
     
    15431559                        if(s.getInterestingTags().isEmpty()){
    15441560                            //load original model
    1545                             loadSVMmodel(false);
    1546                             createOSMObject(sel, false); //create object without class features
     1561                            modelWithClasses = false;
     1562                            loadSVMmodel();
     1563                            createOSMObject(sel); //create object without class features
    15471564                        }
    15481565                        else{
     
    15501567                            if(useTagsCheckBox.isSelected()){
    15511568                                //load model with classes
    1552                                 loadSVMmodel(true);
    1553                                 createOSMObject(sel, true); //create object including class features
     1569                                modelWithClasses = true;
     1570                                loadSVMmodel();
     1571                                createOSMObject(sel); //create object including class features
    15541572                            }
    15551573                            else{
    1556                                 loadSVMmodel(false);
    1557                                 createOSMObject(sel, false); //create object including class features   
     1574                                modelWithClasses = false;
     1575                                loadSVMmodel();
     1576                                createOSMObject(sel); //create object including class features   
    15581577                            }
    15591578                        }                       
     
    15791598                        if(s.getInterestingTags().isEmpty()){
    15801599                            //load original model
    1581                             loadSVMmodel(false);
    1582                             createOSMObject(sel, false); //create object without class features
     1600                            modelWithClasses = false;
     1601                            loadSVMmodel();
     1602                            createOSMObject(sel); //create object without class features
    15831603                        }
    15841604                        else{
     
    15861606                            if(useTagsCheckBox.isSelected()){
    15871607                                //load model with classes
    1588                                 loadSVMmodel(true);
    1589                                 createOSMObject(sel, true); //create object including class features
     1608                                modelWithClasses = true;
     1609                                loadSVMmodel();
     1610                                createOSMObject(sel); //create object including class features
    15901611                            }
    15911612                            else{
    1592                                 loadSVMmodel(false);
    1593                                 createOSMObject(sel, false); //create object including class features   
     1613                                modelWithClasses = false;
     1614                                loadSVMmodel();
     1615                                createOSMObject(sel); //create object including class features   
    15941616                            }
    15951617                        }                       
     
    16491671                File modelWithClassesFile = new File(modelWithClassesPath);
    16501672                if(s.getInterestingTags().isEmpty() || !modelWithClassesFile.exists()){
    1651                     loadSVMmodel(false);//load original model
    1652                     createOSMObject(sel, false); //create object without class features
     1673                    modelWithClasses = false;
     1674                    loadSVMmodel();//load original model
     1675                    createOSMObject(sel); //create object without class features
    16531676                   
    16541677                   
    16551678                }
    16561679                else{
    1657                     loadSVMmodel(true);//load model with classes         
    1658                     createOSMObject(sel, true); //create object including class features                             
     1680                    modelWithClasses = true;
     1681                    loadSVMmodel();//load model with classes         
     1682                    createOSMObject(sel); //create object including class features                             
    16591683                }                       
    16601684            }
     
    19381962        }
    19391963
    1940         private void loadSVMmodel(boolean modelWithClasses) {
     1964        private void loadSVMmodel() {
    19411965            if(useCombinedModel){
    19421966                System.out.println("Using combined model.");
     
    19481972           
    19491973            File modelFile;
    1950             if(modelWithClasses){
    1951                 modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes");
    1952             }
    1953             else {
    1954                 modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model");
    1955             }
     1974            if(useCustomSVMModel){
     1975                System.out.println("using custom model: " + customSVMModelPath);
     1976                modelFile = new File(customSVMModelPath);
     1977            }
     1978            else{
     1979                if(modelWithClasses){
     1980                    System.out.println("using model with classes: " + modelDirectory.getAbsolutePath() + "/model_with_classes");
     1981                    modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes");
     1982                }
     1983                else {
     1984                    System.out.println("using best model: " + modelDirectory.getAbsolutePath() + "/best_model");
     1985                    modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model");
     1986                }               
     1987            }
     1988
    19561989
    19571990           
    19581991            try {
    19591992                modelSVM = Model.load(modelFile);
    1960                 System.out.println("model loaded: " + modelFile.getAbsolutePath());
     1993                //System.out.println("model loaded: " + modelFile.getAbsolutePath());
    19611994            } catch (IOException ex) {
    19621995                Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
     
    22332266        }
    22342267
    2235         private void createOSMObject(Collection<OsmPrimitive> sel, boolean useClassFeatures) {
     2268        private void createOSMObject(Collection<OsmPrimitive> sel) {
    22362269                       
    22372270            MathTransform transform = null;
     
    22702303                for(Node node : selectedWayNodes){
    22712304                    node.getCoor();
    2272                     System.out.println(node.getCoor());
     2305                    //System.out.println(node.getCoor());
    22732306                    if(node.isLatLonKnown()){
    22742307                        //LatLon coord = nod.getCoor();
     
    23392372                classifier.calculateClasses(selectedInstance, mappings, mapperWithIDs, indirectClasses, indirectClassesWithIDs);
    23402373               
    2341                 if(useClassFeatures){
     2374                if(modelWithClasses){
    23422375                    ClassFeatures classFeatures = new ClassFeatures();
    23432376                    classFeatures.createClassFeatures(selectedInstance, mappings, mapperWithIDs, indirectClasses, indirectClassesWithIDs);
     
    23732406                   
    23742407                    mapLabelsToIDs.put(modelSVMLabels[h], h);
    2375                     System.out.println(h + "   <->    " + modelSVMLabels[h]);
     2408                    //System.out.println(h + "   <->    " + modelSVMLabels[h]);
    23762409                   
    23772410                }               
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/TrainByUser.java

    r31106 r31441  
    88import de.bwaldvogel.liblinear.Problem;
    99import de.bwaldvogel.liblinear.SolverType;
     10import java.awt.event.ActionEvent;
     11import java.awt.event.ActionListener;
    1012import java.io.BufferedWriter;
    1113import java.io.File;
     
    2426import java.util.List;
    2527import java.util.Map;
     28import java.util.concurrent.ExecutionException;
    2629import java.util.logging.Level;
    2730import java.util.logging.Logger;
     31import javax.swing.SwingWorker;
    2832import org.openstreetmap.josm.plugins.container.OSMRelation;
    2933import org.openstreetmap.josm.plugins.container.OSMWay;
     
    4549 */
    4650
    47 public class TrainByUser {
     51public class TrainByUser extends SwingWorker<Void, Void> implements ActionListener{
    4852   
    4953    private final String inputFilePath;
     
    6771    private static double foldScore10 = 0;
    6872    private static double bestScore = 0;
    69     int trainProgress = 0;
     73    //int trainProgress = 0;
    7074    private final boolean validateFlag;
    7175    private final double cParameterFromUser;
     
    7579    private final boolean topKIsSelected;
    7680    private String textualListFilePath;   
    77     private static boolean USE_CLASS_FEATURES = false;
    78     private static boolean USE_RELATION_FEATURES = false;
    79     private static boolean USE_TEXTUAL_FEATURES = true;
     81    private static final boolean USE_CLASS_FEATURES = false;
     82    private static final boolean USE_RELATION_FEATURES = false;
     83    private static final boolean USE_TEXTUAL_FEATURES = true;
    8084    private static int numberOfFeatures;
    8185    private static LanguageDetector languageDetector;
     
    108112        TrainByUser.wayList = wayList;
    109113    }
    110    
    111    
    112     public void executeTraining(){       
     114       
     115    @Override
     116    public Void doInBackground() throws Exception {        
    113117        extractTextualList();
    114118        parseFiles();
    115         if(validateFlag){           
     119        if(validateFlag){   
     120            firePropertyChange("progress", getProgress(), 5);
     121            //setProgress(5);
    116122            validateLoop();
     123            firePropertyChange("progress", getProgress(), 40);
     124            //setProgress(40);
    117125            System.out.println("Training model with the best c: " + bestConfParam);
    118126            clearDataset();
    119127            trainModel(bestConfParam);
     128            firePropertyChange("progress", getProgress(), 60);
     129            //setProgress(80);
    120130            clearDataset();
    121131            trainModelWithClasses(bestConfParam);
    122            
     132            firePropertyChange("progress", getProgress(), 100);
     133            setProgress(100);
    123134        }
    124135        else{
     136
     137            //firePropertyChange("progress", getProgress(), 5);
     138            //setProgress(5);
    125139            clearDataset();
     140            firePropertyChange("progress", getProgress(), 10);
     141            //setProgress(10);
    126142            trainModel(cParameterFromUser);
     143            //setProgress(60);   
     144            firePropertyChange("progress", getProgress(), 60);
    127145            clearDataset();
    128             trainModelWithClasses(cParameterFromUser);
     146            firePropertyChange("progress", getProgress(), 65);
     147            //setProgress(65);
     148            trainModelWithClasses(cParameterFromUser);         
     149           
     150            firePropertyChange("progress", getProgress(), 100);
     151            setProgress(100);
    129152            System.out.println("done.");
    130153        }
    131         System.out.println("Train by user process complete.");       
     154        System.out.println("Train by user process complete.");   
     155        return null;
    132156    }
    133157   
     
    232256       
    233257        for(Double param : confParams){
    234            
     258            //setProgress(4*((5*(trainProgress++))/confParams.length));
    235259            foldScore1 = 0;
    236260            foldScore5 = 0;
     
    238262            System.out.println("\n\n\nrunning for C = " + param);
    239263            clearDataset();
    240             System.out.println("fold1");
     264            System.out.println("fold1");           
    241265            //crossValidateFold(0, 3, 3, 4, false, param);
    242266            crossValidateFold(0, 4, 4, 5, false, param); //4-1
     
    294318           
    295319        }
    296         System.out.println(4*((5*(trainProgress++))/confParams.length));
     320        //System.out.println(4*((5*(trainProgress++))/confParams.length));
    297321        //setProgress(100);
    298322        bestConfParam = bestC;
     
    319343        //set classes for each osm instance
    320344        int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size
    321         int lalala = 0;
    322345        for(OSMWay way : trainList){
    323346
     
    326349
    327350            if(way.getClassIDs().isEmpty()){
    328                 wayListSizeWithoutUnclassified = wayListSizeWithoutUnclassified-1;
     351                wayListSizeWithoutUnclassified -= 1;
    329352                u++;
    330353            }
     
    382405                }               
    383406                for(int classID : way.getClassIDs()){
    384                     lalala++;
    385407                    trainingSetWithUnknown2[k] = featureNodeArray;
    386408                    GROUPS_ARRAY2[k] = classID;
     
    472494            if(way.getClassIDs().isEmpty()){
    473495                //System.out.println("found unclassified" + way.getClassIDs() + "class: " +way.getClassID());
    474                 wayListSizeWithoutUnclassified2 = wayListSizeWithoutUnclassified2-1;
     496                wayListSizeWithoutUnclassified2 -= 1;
    475497                //u++;
    476498            }
     
    582604       
    583605        System.out.println("Succeeded " + succededInstances + " of " + testList.size() + " total (1 class prediction)");
    584         double precision1 = (double)succededInstances/(double)wayListSizeWithoutUnclassified2;
     606        double precision1 = succededInstances/(double)wayListSizeWithoutUnclassified2;
    585607        score1 = precision1;
    586608        System.out.println(precision1);
    587609       
    588610        System.out.println("Succeeded " + succededInstances5 + " of " + testList.size()+ " total (5 class prediction)");
    589         double precision5 = (double)succededInstances5/(double)wayListSizeWithoutUnclassified2;
     611        double precision5 = succededInstances5/(double)wayListSizeWithoutUnclassified2;
    590612        score5 = precision5;
    591613        System.out.println(precision5);
    592614       
    593615        System.out.println("Succeeded " + succededInstances10 + " of " + testList.size()+ " total (10 class prediction)");
    594         double precision10 = (double)succededInstances10/(double)wayListSizeWithoutUnclassified2;
     616        double precision10 = succededInstances10/(double)wayListSizeWithoutUnclassified2;
    595617        score10 = precision10;
    596618        System.out.println(precision10);               
     
    602624        int u = 0;
    603625        System.out.println("trainList size: " + wayListSizeWithoutUnclassified);
    604        
    605626        //set classes for each osm instance
    606627        int sizeToBeAddedToArray = 0; //this will be used to proper init the features array, adding the multiple vectors size
    607         int lalala = 0;
    608628
    609629        //System.out.println("starting classify instances");
     
    614634
    615635            if(way.getClassIDs().isEmpty()){
    616                 wayListSizeWithoutUnclassified = wayListSizeWithoutUnclassified-1;
     636                wayListSizeWithoutUnclassified -= 1;
    617637                u++;
    618638            }
     
    672692                }               
    673693                for(int classID : way.getClassIDs()){
    674                     lalala++;
    675694                    trainingSetWithUnknown2[k] = featureNodeArray;
    676695                    GROUPS_ARRAY2[k] = classID;
     
    744763
    745764            if(way.getClassIDs().isEmpty()){
    746                 wayListSizeWithoutUnclassified = wayListSizeWithoutUnclassified-1;
     765                wayListSizeWithoutUnclassified -= 1;
    747766                u++;
    748767            }
     
    888907        }       
    889908    }
     909   
     910    @Override
     911    protected void done() {
     912        try {
     913            System.out.println("Training process complete! - > " + get());
     914            firePropertyChange("progress", getProgress(), 100);
     915            setProgress(100);
     916        }
     917        catch (InterruptedException | ExecutionException ignore) {
     918            System.out.println("Exception: " + ignore);
     919        }
     920    }     
     921   
     922    @Override
     923    public void actionPerformed(ActionEvent ae) {
     924        //cancel button, end process after clearing Dataset
     925    }   
    890926}
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/UserDataExtractAndTrainWorker.java

    r31106 r31441  
    11package org.openstreetmap.josm.plugins.osmrec.personalization;
    22
     3import java.awt.event.ActionEvent;
     4import java.awt.event.ActionListener;
     5import java.beans.PropertyChangeEvent;
     6import java.beans.PropertyChangeListener;
    37import java.text.SimpleDateFormat;
    48import java.util.ArrayList;
     
    711import java.util.List;
    812import java.util.TimeZone;
    9 import java.util.logging.Level;
    10 import java.util.logging.Logger;
    1113import javax.swing.SwingWorker;
    12 import org.opengis.referencing.FactoryException;
    1314import org.openstreetmap.josm.plugins.container.OSMWay;
    14 import org.openstreetmap.josm.plugins.core.TrainWorker;
    1515import org.openstreetmap.josm.plugins.extractor.LanguageDetector;
    1616import org.openstreetmap.josm.plugins.parsers.OSMParser;
     
    2222 */
    2323
    24 public class UserDataExtractAndTrainWorker extends SwingWorker<Void, Void> {
     24public class UserDataExtractAndTrainWorker extends SwingWorker<Void, Void> implements ActionListener{
    2525   
    2626    private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
     
    2828    private final String username;
    2929    private final Integer days;
    30     private List<OSMWay> wayList;
     30    private List<OSMWay> wayList = new ArrayList<>();
    3131    private final boolean byArea;
    3232    private final String inputFilePath;
     
    3737    private final boolean topKIsSelected;
    3838    private final LanguageDetector languageDetector;
     39    private int userTrainProgress = 0;
    3940   
    4041    public UserDataExtractAndTrainWorker(String inputFilePath, String username, Integer days, boolean byArea, boolean validateFlag,
     
    5657    @Override
    5758    protected Void doInBackground() throws Exception {
     59       
     60        System.out.println("UserDataExtractAndTrainWorker doInBackground initiating..");
    5861        if(byArea){
    5962           extractByArea();
     
    6669                cParameterFromUser, topK, frequency, topKIsSelected, languageDetector, wayList);
    6770
    68         trainByUser.executeTraining();
     71        System.out.println("trainByUser executing..");
     72        trainByUser.addPropertyChangeListener(new PropertyChangeListener() {
     73                           
     74            @Override
     75            public void propertyChange(PropertyChangeEvent evt) {
     76                if("progress".equals(evt.getPropertyName())) {
     77                    int progress = (Integer) evt.getNewValue();
     78                    System.out.println("progress++ from property change listener, progress: " + progress);
     79                    setProgress(progress);
     80                   
     81                }
     82            }                                                 
     83        });
     84       
     85       
     86       
     87       
     88       
     89        trainByUser.doInBackground();
     90        setProgress(100);
    6991        return null;
    7092    }
    7193   
    7294    private void extractHistory() {
    73         wayList.clear();
     95        if(wayList != null){
     96            wayList.clear();
     97        }
     98       
    7499        produceTimeIntervals(days);
    75100        HistoryParser historyParser = new HistoryParser(username);
     
    83108   
    84109    private void extractByArea() {
    85         wayList.clear();
    86         OSMParser osmParser = null;
    87         try {
    88             osmParser = new OSMParser(inputFilePath);
    89            
    90         } catch (FactoryException ex) {
    91             Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex);
    92         }
     110        System.out.println("Extracting by Area..");
     111
     112        if(wayList != null){
     113            wayList.clear();
     114        }
     115        //System.out.println("wayList cleared.");
     116       
     117        OSMParser osmParser = new OSMParser(inputFilePath);
     118        osmParser.parseDocument();
     119
     120        //System.out.println("OSMParser done.");
    93121       
    94122        List<OSMWay> completeWayList = osmParser.getWayList();
     123        System.out.println("completeWayList size: " + completeWayList.size());
     124        System.out.println("populating wayList with edits from username: " + username);
    95125        for(OSMWay way : completeWayList){
     126            //System.out.println("current way user: " + way.getUser());
    96127            if(way.getUser().equals(username)){
     128                System.out.println("found user edit!");
    97129                wayList.add(way);
    98130            }           
    99131        }
     132        System.out.println("weeding wayList by user done.");
     133        if(wayList.isEmpty()){
     134            System.out.println("User has not edited this Area. Try \"By time\" option.");
     135        }
     136        else{
     137            System.out.println("User has edited " + wayList.size() + " OSM entities in this area.");
     138        }
    100139    }   
    101140   
     
    142181        } while(cal.getTime().before(currentDate));
    143182    }
     183
     184    @Override
     185    public void actionPerformed(ActionEvent ae) {
     186        //this.firePropertyChange("progress", userTrainProgress, userTrainProgress+10);
     187//        if(userTrainProgress <100){
     188//            setProgress(userTrainProgress+10);
     189//        }
     190       
     191    }
    144192}
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/OSMParser.java

    r31106 r31441  
    4848    private static final CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN;
    4949    private final GeometryFactory geometryFactory = new GeometryFactory();
    50     private final MathTransform transform;
     50    private static MathTransform transform = null;
    5151    private final List<OSMNode> nodeList; //will be populated with nodes
    5252    private final List<OSMRelation> relationList;
     
    6161    private boolean inRelation = false; //becomes true when the parser is in a relarion node
    6262   
    63     public OSMParser(String osmXmlFileName) throws FactoryException {
     63    public OSMParser(String osmXmlFileName)  {
     64        //System.out.println("creating osmParser..");
    6465        this.osmXmlFileName = osmXmlFileName;       
    6566        nodeList = new ArrayList<>();
     
    6768        relationList = new ArrayList<>();
    6869        nodesWithIDs = new HashMap<>();
    69         transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
     70        try {
     71            transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
     72        } catch (FactoryException ex) {
     73            Logger.getLogger(OSMParser.class.getName()).log(Level.SEVERE, null, ex);
     74        }
     75        //System.out.println("osmParser created!");
    7076    }
    7177
     
    117123            wayTmp = new OSMWay();
    118124            wayTmp.setID(attributes.getValue("id"));
    119             wayTmp.setUser(attributes.getValue("user"));
     125           
     126            if(attributes.getValue("user") != null){
     127                wayTmp.setUser(attributes.getValue("user"));
     128            }
     129            else{
     130                wayTmp.setUser("undefined");
     131            }
     132            //System.out.println("way user: " + attributes.getValue("user"));
     133                   
    120134            inWay = true;
    121135            inNode = false;
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/Ontology.java

    r31402 r31441  
    5050        ontologyModel = ModelFactory.createOntologyModel();               
    5151       
    52         //org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.ERROR);
     52        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.ERROR);
    5353        ontologyModel.read(owlFile, null);    //Hide RDFDefaultErrorHandler from terminal to keep clear output.
    54         //org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
     54        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
    5555   
    5656        listHierarchy = ontologyModel.listHierarchyRootClasses().toList();
     
    6565            if (obj.hasSubClass()) {
    6666
    67                 for (Iterator i = obj.listSubClasses(true); i.hasNext();) {
    68                     OntClass currentClass = (OntClass) i.next();
     67                for (Iterator<OntClass> i = obj.listSubClasses(true); i.hasNext();) {
     68                    OntClass currentClass = i.next();
    6969                   
    7070                    List<OntClass> superClasses = currentClass.listSuperClasses().toList();                   
Note: See TracChangeset for help on using the changeset viewer.