Changeset 9286:bbcedbcdc1fc in orange


Ignore:
Timestamp:
11/29/11 15:37:23 (2 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
a03c3792a9095e3d17a1839a66a1345c7e49411a
Message:

Mapped names can reference class members inside packages (package namespace is separated by ':').
Added orngEnviron name maps.
Added some orngTree mapped names.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/fixes/fix_changed_names.py

    r9148 r9286  
    11""" This fixer changes all occurrences of the form 'module.member' from the 
    22global dictionary MAPPING's keys and replaces them with the corresponding 
    3 value. It adds the proper imports to make it available in the script 
     3value. It adds the proper imports to make it available in the script.  
    44 
    55For example this code:: 
     
    1212    import Orange.data 
    1313    import Orange.classification.svm 
    14     data =Orange.data.Table('iris') 
    15     learner =Orange.classification.svm.SVMLearner(name='svm') 
     14    data = Orange.data.Table('iris') 
     15    learner = Orange.classification.svm.SVMLearner(name='svm') 
    1616     
    1717Try to add as much name mappings as possible (This fixer is prefered  
     
    2424from lib2to3.fixer_util import Name, Dot, Node, attr_chain, touch_import 
    2525 
    26 # keys must be in the form of 'orange.name' not name or orange.bla.name  
     26# Keys must be in the form of 'orange.name' not name or orange.bla.name  
     27# If the values name a doted name inside of the package the package and name 
     28# must be separated by ':' e.g. Orange.classification:Classifier.GetValue 
     29# indicates Classifier.GetValue is a name inside package Orange.classification, 
     30# do not use Orange.classification.Classifier.GetValue as this is assumed that  
     31# Orange.classification.Classifier is a package 
     32#  
    2733MAPPING = {"orange.ExampleTable": "Orange.data.Table", 
    2834           "orange.Example": "Orange.data.Instance", 
     
    3743           "orange.VarList": "Orange.data.variable.Variables", 
    3844           "orange.SymMatrix": "Orange.data.SymMatrix", 
    39            "orange.GetValue": "Orange.classification.Classifier.GetValue", 
    40            "orange.GetProbabilities": "Orange.classification.Classifier.GetProbabilities", 
    41            "orange.GetBoth": "Orange.classification.Classifier.GetBoth", 
     45           "orange.GetValue": "Orange.classification:Classifier.GetValue", 
     46           "orange.GetProbabilities": "Orange.classification:Classifier.GetProbabilities", 
     47           "orange.GetBoth": "Orange.classification:Classifier.GetBoth", 
    4248            
    4349           "orange.Distribution": "Orange.statistics.distribution.Distribution", 
     
    125131            
    126132           "orange.HierarchicalClustering": "Orange.clustering.hierarchical.HierarchicalClustering", 
     133           "orange.HierarchicalCluster": "Orange.clustering.hierarchical.HierarchicalCluster", 
    127134           "orngClustering.hierarchicalClustering": "Orange.clustering.hierarchical.clustering", 
    128135           "orngClustering.hierarchicalClustering_attributes": "Orange.clustering.hierarchical.clustering_features", 
     
    131138           "orngClustering.hierarhicalClustering_topClustersMembership": "Orange.clustering.hierarchical.top_cluster_membership", 
    132139           "orngClustering.orderLeaves": "Orange.clustering.hierarchical.order_leaves", 
     140           "orngClustering.dendrogram_draw": "Orange.clustering.hierarchical.dendrogram_draw", 
     141           "orngClustering.DendrogramPlot": "Orange.clustering.hierarchical.DendrogramPlot", 
     142           "orngClustering.DendrogramPlotPylab": "Orange.clustering.hierarchical.DendrogramPlotPylab", 
    133143            
    134144           "orngSVM.RBFKernelWrapper": "Orange.classification.svm.kernels.RBFKernelWrapper", 
     
    141151           "orngSVM.SparseLinKernel": "Orange.classification.svm.kernels.SparseLinKernel", 
    142152           "orngSVM.BagOfWords": "Orange.classification.svm.kernels.BagOfWords", 
     153           "orngSVM.SVMLearner": "Orange.classification.svm.SVMLearner", 
     154           "orngSVM.SVMLearnerEasy": "Orange.classification.svm.SVMLearnerEasy", 
     155           "orngSVM.SVMLearnerSparse": "Orange.classification.svm.SVMLearnerSparse", 
    143156            
    144157           "orange.kNNLearner":"Orange.classification.knn.kNNLearner", 
     
    200213           "orange.TreeStopCriteria_Python":"Orange.classification.tree.StopCriteria_Python", 
    201214           "orange.TreeStopCriteria_common":"Orange.classification.tree.StopCriteria_common", 
     215            
     216           "orngTree.printTxt": "Orange.classification.tree:TreeClassifier.dump", 
     217           "orngTree.printDot": "Orange.classification.tree:TreeClassifier.dot", 
    202218            
    203219           "orange.MajorityLearner":"Orange.classification.majority.MajorityLearner", 
     
    374390           #"orngMisc.compare2_smaller":"Orange.misc.selection.compareSmaller", 
    375391            
     392           "orngMisc.Renderer": "Orange.misc.render.Renderer", 
     393           "orngMisc.EPSRenderer": "Orange.misc.render.EPSRenderer", 
     394           "orngMisc.SVGRenderer": "Orange.misc.render.SVGRenderer", 
     395           "orngMisc.PILRenderer": "Orange.misc.render.PILRenderer", 
     396           # The rest of orngMisc is handled by fix_orange_imports (maps to Orange.misc)  
     397            
    376398           "orngEnsemble.BaggedLearner":"Orange.ensemble.bagging.BaggedLearner", 
    377399           "orngEnsemble.BaggedClassifier":"Orange.ensemble.bagging.BaggedClassifier", 
    378            "orngEnsemble.BoostedLearner":"Orange.boosting.BoostedLearner", 
     400           "orngEnsemble.BoostedLearner":"Orange.ensemble.boosting.BoostedLearner", 
    379401           "orngEnsemble.BoostedClassifier":"Orange.ensemble.boosting.BoostedClassifier", 
    380402           "orngEnsemble.RandomForestClassifier":"Orange.ensemble.forest.RandomForestClassifier", 
     
    396418           "orngTest.ExperimentResults":"Orange.evaluation.testing.ExperimentResults", 
    397419 
     420           "orngLR.dump":"Orange.classification.logreg.dump", 
    398421           "orngLR.printOUT":"Orange.classification.logreg.dump", 
    399422           "orngLR.printOut":"Orange.classification.logreg.dump", 
     
    480503           "orngLinProj.S2NHeuristicLearner": "Orange.projection.linear.S2NHeuristicLearner", 
    481504            
     505           "orngDisc.entropyDiscretization": "Orange.feature.discretization.entropyDiscretization_wrapper", 
     506           "orngDisc.EntropyDiscretization": "Orange.feature.discretization.EntropyDiscretization_wrapper", 
     507            
     508           "orange.ProbabilityEstimator": "Orange.statistics.estimate.ProbabilityEstimator", 
     509           "orange.ProbabilityEstimator_FromDistribution": "Orange.statistics.estimate.ProbabilityEstimator_FromDistribution", 
     510           "orange.ProbabilityEstimatorConstructor": "Orange.statistics.estimate.ProbabilityEstimatorConstructor", 
     511           "orange.ProbabilityEstimatorConstructor_Laplace": "Orange.statistics.estimate.ProbabilityEstimatorConstructor_Laplace", 
     512           "orange.ProbabilityEstimatorConstructor_kernel": "Orange.statistics.estimate.ProbabilityEstimatorConstructor_kernel", 
     513           "orange.ProbabilityEstimatorConstructor_loess": "Orange.statistics.estimate.ProbabilityEstimatorConstructor_loess", 
     514           "orange.ProbabilityEstimatorConstructor_m": "Orange.statistics.estimate.ProbabilityEstimatorConstructor_m", 
     515           "orange.ProbabilityEstimatorConstructor_relative": "Orange.statistics.estimate.ProbabilityEstimatorConstructor_relative", 
     516           "orange.ProbabilityEstimatorList": "Orange.statistics.estimate.ProbabilityEstimatorList", 
     517            
     518           "orange.FilterList": "Orange.preprocess.FilterList", 
     519           "orange.Filter": "Orange.preprocess.Filter", 
     520           "orange.Filter_conjunction": "Orange.preprocess.Filter_conjunction", 
     521           "orange.Filter_disjunction": "Orange.preprocess.Filter_disjunction", 
     522           "orange.Filter_hasClassValue": "Orange.preprocess.Filter_hasClassValue", 
     523           "orange.Filter_hasMeta": "Orange.preprocess.Filter_hasMeta", 
     524           "orange.Filter_hasSpecial": "Orange.preprocess.Filter_hasSpecial", 
     525           "orange.Filter_isDefined": "Orange.preprocess.Filter_isDefined", 
     526           "orange.Filter_random": "Orange.preprocess.Filter_random", 
     527           "orange.Filter_sameValue": "Orange.preprocess.Filter_sameValue", 
     528           "orange.Filter_values": "Orange.preprocess.Filter_values", 
     529            
     530           # orngEnviron 
     531            
     532           "orngEnviron.orangeDir": "Orange.misc.environ.install_dir", 
     533           "orngEnviron.orangeDocDir": "Orange.misc.environ.doc_install_dir", 
     534           "orngEnviron.orangeVer": "Orange.misc.environ.version", 
     535           "orngEnviron.canvasDir": "Orange.misc.environ.canvas_install_dir", 
     536           "orngEnviron.widgetDir": "Orange.misc.environ.widget_install_dir", 
     537           "orngEnviron.picsDir": "Orange.misc.environ.icons_install_dir", 
     538           "orngEnviron.addOnsDirSys": "Orange.misc.environ.add_ons_dir", 
     539           "orngEnviron.addOnsDirUser": "Orange.misc.environ.add_ons_dir_user", 
     540           "orngEnviron.applicationDir": "Orange.misc.environ.application_dir", 
     541           "orngEnviron.outputDir": "Orange.misc.environ.output_dir", 
     542           "orngEnviron.defaultReportsDir": "Orange.misc.environ.default_reports_dir", 
     543           "orngEnviron.orangeSettingsDir": "Orange.misc.environ.orange_settings_dir", 
     544           "orngEnviron.widgetSettingsDir": "Orange.misc.environ.widget_settings_dir", 
     545           "orngEnviron.canvasSettingsDir": "Orange.misc.environ.canvas_settings_dir", 
     546           "orngEnviron.bufferDir": "Orange.misc.environ.buffer_dir", 
     547           "orngEnviron.directoryNames": "Orange.misc.environ.directories", 
     548           "orngEnviron.samepath": "Orange.misc.environ.samepath", 
     549           "orngEnviron.addOrangeDirectoriesToPath": "Orange.misc.environ.add_orange_directories_to_path", 
     550                       
    482551           "orngScaleData.getVariableValuesSorted": "Orange.preprocess.scaling.get_variable_values_sorted", 
    483552           "orngScaleData.getVariableValueIndices": "Orange.preprocess.scaling.get_variable_value_indices", 
     
    573642            if old_name not in self.mapping: 
    574643                return 
    575               
    576             new_name = unicode(self.mapping[module + "." + node.value]) 
    577644             
     645            new_name = unicode(self.mapping[old_name]) 
     646             
     647            if ":" in new_name: 
     648                # ':' is the delimiter used to separate module namespace 
     649                package = new_name.split(":",1)[0] 
     650                new_name = new_name.replace(":", ".") 
     651            else: 
     652                package = new_name.rsplit(".", 1)[0] 
     653                 
    578654            syms = self.syms 
    579655             
     
    584660             
    585661            # Make sure the proper package is imported 
    586             package = new_name.rsplit(".", 1)[0] 
     662#            if ":" in new_name: 
     663#                package = new_name.split(":",1)[0] 
     664#            else: 
     665#                package = new_name.rsplit(".", 1)[0] 
    587666            touch_import(None, package, node) 
    588             return new     
    589      
     667            return new 
     668         
Note: See TracChangeset for help on using the changeset viewer.