source: orange/Orange/fixes/fix_changed_names.py @ 9912:722bb5ff85c3

Revision 9912:722bb5ff85c3, 45.2 KB checked in by gregorr, 2 years ago (diff)

Changed Orange.data.SymMatrix -> Orange.misc.SymMatrix in fix_changed_names.py.

Line 
1""" This fixer changes all occurrences of the form 'module.member' from the
2global dictionary MAPPING's keys and replaces them with the corresponding
3value. It adds the proper imports to make it available in the script.
4
5For example this code::
6    import orange
7    import orngSVM
8    data = orange.ExampleTable("iris")
9    learner = orngSVM.SVMLearner(name='svm')
10   
11will be replaced with::
12    import Orange.data
13    import Orange.classification.svm
14    data = Orange.data.Table('iris')
15    learner = Orange.classification.svm.SVMLearner(name='svm')
16   
17Try to add as much name mappings as possible (This fixer is prefered
18(and will run before) the fix_orange_imports 
19   
20"""
21from lib2to3 import fixer_base
22from lib2to3 import pytree
23from lib2to3.fixer_util import Name, Dot, touch_import
24
25# Keys must be in the form of 'orange.name' not name or orange.bla.name
26# If the values name a doted name inside of the package the package and name
27# must be separated by ':' e.g. Orange.classification:Classifier.GetValue
28# indicates Classifier.GetValue is a name inside package Orange.classification,
29# do not use Orange.classification.Classifier.GetValue as this is assumed that
30# Orange.classification.Classifier is a package
31#
32MAPPING = {"orange.ExampleTable": "Orange.data.Table",
33           "orange.Example": "Orange.data.Instance",
34           "orange.Domain": "Orange.data.Domain",
35           "orange.Value": "Orange.data.Value",
36           "orange.VarTypes": "Orange.data.Type",
37           "orange.Variable": "Orange.data.variable.Variable",
38           "orange.EnumVariable": "Orange.data.variable.Discrete",
39           "orange.FloatVariable": "Orange.data.variable.Continuous",
40           "orange.StringVariable": "Orange.data.variable.String",
41           "orange.PythonVariable": "Orange.data.variable.Python",
42           "orange.VarList": "Orange.data.variable.Variables",
43           "orange.SymMatrix": "Orange.misc.SymMatrix",
44           "orange.GetValue": "Orange.classification:Classifier.GetValue",
45           "orange.GetProbabilities": "Orange.classification:Classifier.GetProbabilities",
46           "orange.GetBoth": "Orange.classification:Classifier.GetBoth",
47
48           "orange.newmetaid": "Orange.data.new_meta_id",
49
50           "orange.Distribution": "Orange.statistics.distribution.Distribution",
51           "orange.DiscDistribution": "Orange.statistics.distribution.Discrete",
52           "orange.ContDistribution": "Orange.statistics.distribution.Continuous",
53           "orange.GaussianDistribution": "Orange.statistics.distribution.Gaussian",
54           "orange.DomainDistributions": "Orange.statistics.distribution.Domain",
55
56           "orange.BasicAttrStat": "Orange.statistics.basic.Variable",
57           "orange.DomainBasicAttrStat": "Orange.statistics.basic.Domain",
58
59           "orange.ContingencyAttrAttr": "Orange.statistics.contingency.VarVar",
60           "orange.ContingencyClass": "Orange.statistics.contingency.Class",
61           "orange.ContingencyAttrClass": "Orange.statistics.contingency.VarClass",
62           "orange.ContingencyClassAttr": "Orange.statistics.contingency.ClassVar",
63           "orange.DomainContingency": "Orange.statistics.contingency.Domain",
64           "orange.Contingency": "Orange.statistics.contingency.Table",
65
66           "orange.MeasureAttribute": "Orange.feature.scoring.Score",
67           "orange.MeasureAttributeFromProbabilities": "Orange.feature.scoring.ScoreFromProbabilities",
68           "orange.MeasureAttribute_gainRatio": "Orange.feature.scoring.GainRatio",
69           "orange.MeasureAttribute_relief": "Orange.feature.scoring.Relief",
70           "orange.MeasureAttribute_info": "Orange.feature.scoring.InfoGain",
71           "orange.MeasureAttribute_gini": "Orange.feature.scoring.Gini",
72
73           "orange.MeasureAttribute_relevance": "Orange.feature.scoring.Relevance",
74           "orange.MeasureAttribute_cost": "Orange.feature.scoring.Cost",
75           "orange.MeasureAttribute_MSE": "Orange.feature.scoring.MSE",
76
77           "orange.EntropyDiscretization": "Orange.feature.discretization.Entropy",
78           "orange.EquiDistDiscretization": "Orange.feature.discretization.EqualWidth",
79           "orange.EquiNDiscretization": "Orange.feature.discretization.EqualFreq",
80           "orange.BiModalDiscretization": "Orange.feature.discretization.BiModal",
81
82           "orngFSS.attMeasure": "Orange.feature.scoring.score_all",
83           "orngFSS.bestNAtts": "Orange.feature.selection.best_n",
84           "orngFSS.attsAbovethreshold": "Orange.feature.selection.above_threshold",
85           "orngFSS.selectBestNAtts": "Orange.feature.selection.select_best_n",
86           "orngFSS.selectAttsAboveThresh": "Orange.feature.selection.select_above_threshold",
87           "orngFSS.filterRelieff": "Orange.feature.selection.select_relief",
88           "orngFSS.FilterAttsAboveThresh": "Orange.feature.selection.FilterAboveThreshold",
89           "orngFSS.FilterAttsAboveThresh_Class": "Orange.feature.selection.FilterAboveThreshold",
90           "orngFSS.FilterBestNAtts": "Orange.feature.selection.FilterBestN",
91           "orngFSS.FilterBestNAtts_Class": "Orange.feature.selection.FilterBestN",
92           "orngFSS.FilterRelief": "Orange.feature.selection.FilterRelief",
93           "orngFSS.FilterRelief_Class": "Orange.feature.selection.FilterRelief",
94           "orngFSS.FilteredLearner": "Orange.feature.selection.FilteredLearner",
95           "orngFSS.FilteredLearner_Class": "Orange.feature.selection.FilteredLearner",
96           "orngFSS.FilteredClassifier": "Orange.feature.selection.FilteredClassifier",
97           "orngFSS.StepwiseLearner_Class": "Orange.classification.wrappers.StepwiseLearner",
98           "orngFSS.StepwiseLearner": "Orange.classification.wrappers.StepwiseLearner",
99
100           "orange.ImputerConstructor_model": "Orange.feature.imputation.ImputerConstructor_model",
101           "orange.Imputer_model": "Orange.feature.imputation.Imputer_model",
102           "orange.Imputer_defaults": "Orange.feature.imputation.Imputer_defaults",
103           "orange.ImputerConstructor_asValue": "Orange.feature.imputation.ImputerConstructor_asValue",
104           "orange.ImputerConstructor_minimal": "Orange.feature.imputation.ImputerConstructor_minimal",
105           "orange.ImputerConstructor_maximal": "Orange.feature.imputation.ImputerConstructor_maximal",
106           "orange.ImputerConstructor_average": "Orange.feature.imputation.ImputerConstructor_average",
107
108           "orange.ExamplesDistance": "Orange.distance.Distance",
109           "orange.ExamplesDistance_Normalized": "Orange.distance.DistanceNormalized",
110           "orange.ExamplesDistanceConstructor": "Orange.distance.DistanceConstructor",
111           "orange.ExamplesDistance_Hamming": "Orange.distance.HammingDistance",
112           "orange.ExamplesDistance_DTW": "Orange.distance.DTWDistance",
113           "orange.ExamplesDistance_Euclidean": "Orange.distance.EuclideanDistance",
114           "orange.ExamplesDistance_Manhattan": "Orange.distance.ManhattanDistance",
115           "orange.ExamplesDistance_Maximal": "Orange.distance.MaximalDistance",
116           "orange.ExamplesDistance_Relief": "Orange.distance.ReliefDistance",
117
118           "orange.ExamplesDistanceConstructor_DTW": "Orange.distance.DTW",
119           "orange.ExamplesDistanceConstructor_Euclidean": "Orange.distance.Euclidean",
120           "orange.ExamplesDistanceConstructor_Hamming": "Orange.distance.Hamming",
121           "orange.ExamplesDistanceConstructor_Manhattan": "Orange.distance.Manhattan",
122           "orange.ExamplesDistanceConstructor_Maximal": "Orange.distance.Maximal",
123           "orange.ExamplesDistanceConstructor_Relief": "Orange.distance.Relief",
124
125           "orngClustering.ExamplesDistanceConstructor_PearsonR": "Orange.distance.PearsonR",
126           "orngClustering.ExamplesDistance_PearsonR": "Orange.distance.PearsonRDistance",
127           "orngClustering.ExamplesDistanceConstructor_SpearmanR": "Orange.distance.SpearmanR",
128           "orngClustering.ExamplesDistance_SpearmanR": "Orange.distance.SpearmanRDistance",
129
130           "orngClustering.KMeans": "Orange.clustering.kmeans.Clustering",
131           "orngClustering.kmeans_init_random": "Orange.clustering.kmeans.init_random",
132           "orngClustering.kmeans_init_diversity": "Orange.clustering.kmeans.init_diversity",
133           "orngClustering.KMeans_init_hierarchicalClustering": "Orange.clustering.kmeans.init_hclustering",
134           "orngClustering.data_center": "Orange.clustering.kmeans.data_center",
135           "orngClustering.plot_silhouette": "Orange.clustering.kmeans.plot_silhouette",
136           "orngClustering.score_distance_to_centroids": "Orange.clustering.kmeans.score_distance_to_centroids",
137           "orngClustering.score_silhouette": "Orange.clustering.kmeans.score_silhouette",
138
139           "orange.HierarchicalClustering": "Orange.clustering.hierarchical.HierarchicalClustering",
140           "orange.HierarchicalCluster": "Orange.clustering.hierarchical.HierarchicalCluster",
141           "orngClustering.hierarchicalClustering": "Orange.clustering.hierarchical.clustering",
142           "orngClustering.hierarchicalClustering_attributes": "Orange.clustering.hierarchical.clustering_features",
143           "orngClustering.hierarchicalClustering_clusterList": "Orange.clustering.hierarchical.cluster_to_list",
144           "orngClustering.hierarchicalClustering_topClusters": "Orange.clustering.hierarchical.top_clusters",
145           "orngClustering.hierarhicalClustering_topClustersMembership": "Orange.clustering.hierarchical.top_cluster_membership",
146           "orngClustering.orderLeaves": "Orange.clustering.hierarchical.order_leaves",
147           "orngClustering.dendrogram_draw": "Orange.clustering.hierarchical.dendrogram_draw",
148           "orngClustering.DendrogramPlot": "Orange.clustering.hierarchical.DendrogramPlot",
149           "orngClustering.DendrogramPlotPylab": "Orange.clustering.hierarchical.DendrogramPlotPylab",
150
151           "orngSVM.RBFKernelWrapper": "Orange.classification.svm.kernels.RBFKernelWrapper",
152           "orngSVM.CompositeKernelWrapper": "Orange.classification.svm.kernels.CompositeKernelWrapper",
153           "orngSVM.KernelWrapper": "Orange.classification.svm.kernels.KernelWrapper",
154           "orngSVM.DualKernelWrapper": "Orange.classification.svm.kernels.DualKernelWrapper",
155           "orngSVM.PolyKernelWrapper": "Orange.classification.svm.kernels.PolyKernelWrapper",
156           "orngSVM.AdditionKernelWrapper": "Orange.classification.svm.kernels.AdditionKernelWrapper",
157           "orngSVM.MultiplicationKernelWrapper": "Orange.classification.svm.kernels.MultiplicationKernelWrapper",
158           "orngSVM.SparseLinKernel": "Orange.classification.svm.kernels.SparseLinKernel",
159           "orngSVM.BagOfWords": "Orange.classification.svm.kernels.BagOfWords",
160           "orngSVM.SVMLearner": "Orange.classification.svm.SVMLearner",
161           "orngSVM.SVMLearnerEasy": "Orange.classification.svm.SVMLearnerEasy",
162           "orngSVM.SVMLearnerSparse": "Orange.classification.svm.SVMLearnerSparse",
163
164           "orange.kNNLearner":"Orange.classification.knn.kNNLearner",
165           "orange.kNNClassifier":"Orange.classification.knn.kNNClassifier",
166           "orange.FindNearest_BruteForce":"Orange.classification.knn.FindNearest",
167           "orange.FindNearestConstructor_BruteForce":"Orange.classification.knn.FindNearestConstructor",
168           "orange.P2NN":"Orange.classification.knn.P2NN",
169
170           "orange.BayesLearner":"Orange.classification.bayes.NaiveLearner",
171           "orange.BayesClassifier":"Orange.classification.bayes.NaiveClassifier",
172           "orngBayes.BayesLearner":"Orange.classification.bayes.NaiveLearner",
173           "orngBayes.BayesClassifier":"Orange.classification.bayes.NaiveClassifier",
174           "orngBayes.printModel": "Orange.classification.bayes.printModel",
175
176           "orngNetwork.MdsTypeClass":"Orange.network.MdsTypeClass",
177           "orngNetwork.Network":"Orange.network.Network",
178           "orngNetwork.NetworkOptimization":"Orange.network.NetworkOptimization",
179           "orngNetwork.NetworkClustering":"Orange.network.NetworkClustering",
180           "orange.Graph":"Orange.network.Graph",
181           "orange.GraphAsList":"Orange.network.GraphAsList",
182           "orange.GraphAsMatrix":"Orange.network.GraphAsMatrix",
183           "orange.GraphAsTree":"Orange.network.GraphAsTree",
184
185           "orange.TreeLearner": "Orange.classification.tree.TreeLearner",
186           "orange.TreeClassifier": "Orange.classification.tree.TreeClassifier",
187           "orange.C45Learner": "Orange.classification.tree.C45Learner",
188           "orange.C45Classifier": "Orange.classification.tree.C45Classifier",
189           "orange.C45TreeNode": "Orange.classification.tree.C45Node",
190           "orange.C45TreeNodeList": "Orange.classification.tree.C45NodeList",
191           "orange.TreeDescender": "Orange.classification.tree.Descender",
192           "orange.TreeDescender_UnknownMergeAsBranchSizes": "Orange.classification.tree.Descender_UnknownMergeAsBranchSizes",
193           "orange.TreeDescender_UnknownMergeAsSelector": "Orange.classification.tree.Descender_UnknownMergeAsSelector",
194           "orange.TreeDescender_UnknownToBranch": "Orange.classification.tree.Descender_UnknownToBranch",
195           "orange.TreeDescender_UnknownToCommonBranch": "Orange.classification.tree.Descender_UnknownToCommonBranch",
196           "orange.TreeDescender_UnknownToCommonSelector":"Orange.classification.tree.Descender_UnknownToCommonSelector",
197           "orange.TreeExampleSplitter":"Orange.classification.tree.Splitter",
198           "orange.TreeExampleSplitter_IgnoreUnknowns":"Orange.classification.tree.Splitter_IgnoreUnknowns",
199           "orange.TreeExampleSplitter_UnknownsAsBranchSizes":"Orange.classification.tree.Splitter_UnknownsAsBranchSizes",
200           "orange.TreeExampleSplitter_UnknownsAsSelecto":"Orange.classification.tree.Splitter_UnknownsAsSelector",
201           "orange.TreeExampleSplitter_UnknownsToAll":"Orange.classification.tree.Splitter_UnknownsToAll",
202           "orange.TreeExampleSplitter_UnknownsToBranch":"Orange.classification.tree.Splitter_UnknownsToBranch",
203           "orange.TreeExampleSplitter_UnknownsToCommon":"Orange.classification.tree.Splitter_UnknownsToCommon",
204           "orange.TreeExampleSplitter_UnknownsToRandom":"Orange.classification.tree.Splitter_UnknownsToRandom",
205           "orange.TreeNode":"Orange.classification.tree.Node",
206           "orange.TreeNodeList":"Orange.classification.tree.NodeList",
207           "orange.TreePruner":"Orange.classification.tree.Pruner",
208           "orange.TreePruner_SameMajority":"Orange.classification.tree.Pruner_SameMajority",
209           "orange.TreePruner_m":"Orange.classification.tree.Pruner_m",
210           "orange.TreeSplitConstructor":"Orange.classification.tree.SplitConstructor",
211           "orange.TreeSplitConstructor_Combined":"Orange.classification.tree.SplitConstructor_Combined",
212           "orange.TreeSplitConstructor_Measure":"Orange.classification.tree.SplitConstructor_Score",
213           "orange.TreeSplitConstructor_Attribute":"Orange.classification.tree.SplitConstructor_Feature",
214           "orange.TreeSplitConstructor_ExhaustiveBinary":"Orange.classification.tree.SplitConstructor_ExhaustiveBinary",
215           "orange.TreeSplitConstructor_OneAgainstOthers":"Orange.classification.tree.SplitConstructor_OneAgainstOthers",
216           "orange.TreeSplitConstructor_Threshold":"Orange.classification.tree.SplitConstructor_Threshold",
217           "orange.TreeStopCriteria":"Orange.classification.tree.StopCriteria",
218           "orange.TreeStopCriteria_Python":"Orange.classification.tree.StopCriteria_Python",
219           "orange.TreeStopCriteria_common":"Orange.classification.tree.StopCriteria_common",
220
221           "orngTree.printTxt": "Orange.classification.tree:TreeClassifier.dump",
222           "orngTree.printTree": "Orange.classification.tree:TreeClassifier.dump",
223           "orngTree.dumpTree": "Orange.classification.tree:TreeClassifier.dump",
224           "orngTree.printDot": "Orange.classification.tree:TreeClassifier.dot",
225           "orngTree.dotTree": "Orange.classification.tree:TreeClassifier.dot",
226           "orngTree.dump": "Orange.classification.tree:TreeClassifier.dump",
227           "orngTree.dot": "Orange.classification.tree:TreeClassifier.dot",
228           "orngTree.countLeaves": "Orange.classification.tree:TreeClassifier.count_leaves",
229           "orngTree.countNodes": "Orange.classification.tree:TreeClassifier.count_nodes",
230           "orngTree.byWhom": "Orange.classification.tree.by_whom",
231           "orngTree.insertStr": "Orange.classification.tree.insert_str",
232           "orngTree.insertDot": "Orange.classification.tree.insert_dot",
233           "orngTree.insertNum": "Orange.classification.tree.insert_num",
234
235           "orange.MajorityLearner":"Orange.classification.majority.MajorityLearner",
236           "orange.DefaultClassifier":"Orange.classification.ConstantClassifier",
237
238           "orange.LookupLearner":"Orange.classification.lookup.LookupLearner",
239           "orange.ClassifierByLookupTable":"Orange.classification.lookup.ClassifierByLookupTable",
240           "orange.ClassifierByLookupTable1":"Orange.classification.lookup.ClassifierByLookupTable1",
241           "orange.ClassifierByLookupTable2":"Orange.classification.lookup.ClassifierByLookupTable2",
242           "orange.ClassifierByLookupTable3":"Orange.classification.lookup.ClassifierByLookupTable3",
243           "orange.ClassifierByExampleTable":"Orange.classification.lookup.ClassifierByDataTable",
244
245           "orngLookup.lookupFromBound":"Orange.classification.lookup.lookup_from_bound",
246           "orngLookup.lookupFromExamples":"Orange.classification.lookup.lookup_from_data",
247           "orngLookup.lookupFromFunction":"Orange.classification.lookup.lookup_from_function",
248           "orngLookup.printLookupFunction":"Orange.classification.lookup.dump_lookup_function",
249
250           "orange.AssociationRule" : "Orange.associate.AssociationRule",
251           "orange.AssociationRules" : "Orange.associate.AssociationRules",
252           "orange.AssociationRulesInducer" : "Orange.associate.AssociationRulesInducer",
253           "orange.AssociationRulesSparseInducer" : "Orange.associate.AssociationRulesSparseInducer",
254           "orange.ItemsetNodeProxy" : "Orange.associate.ItemsetNodeProxy",
255           "orange.ItemsetsSparseInducer" : "Orange.associate.ItemsetsSparseInducer",
256
257           "orngCN2.ruleToString": "Orange.classification.rules.rule_to_string",
258           "orngCN2.LaplaceEvaluator": "Orange.classification.rules.LaplaceEvaluator",
259           "orngCN2.WRACCEvaluator": "Orange.classification.rules.WRACCEvaluator",
260           "orngCN2.mEstimate": "Orange.classification.rules.MEstimateEvaluator",
261           "orngCN2.RuleStopping_apriori": "Orange.classification.rules.RuleStopping_Apriori",
262           "orngCN2.LengthValidator": "Orange.classification.rules.LengthValidator",
263           "orngCN2.supervisedClassCheck": "Orange.classification.rules.supervisedClassCheck",
264           "orngCN2.CN2Learner": "Orange.classification.rules.CN2Learner",
265           "orngCN2.CN2Classifier": "Orange.classification.rules.CN2Classifier",
266           "orngCN2.CN2UnorderedLearner": "Orange.classification.rules.CN2UnorderedLearner",
267           "orngCN2.CN2UnorderedClassifier": "Orange.classification.rules.CN2UnorderedClassifier",
268           "orngCN2.RuleClassifier_bestRule": "Orange.classification.rules.RuleClassifier_BestRule",
269           "orngCN2.CovererAndRemover_multWeights": "Orange.classification.rules.CovererAndRemover_MultWeights",
270           "orngCN2.CovererAndRemover_addWeights": "Orange.classification.rules.CovererAndRemover_AddWeights",
271           "orngCN2.rule_in_set": "Orange.classification.rules.rule_in_set",
272           "orngCN2.rules_equal": "Orange.classification.rules.rules_equal",
273           "orngCN2.noDuplicates_validator": "Orange.classification.rules.NoDuplicatesValidator",
274           "orngCN2.ruleSt_setRules": "Orange.classification.rules.RuleStopping_SetRules",
275           "orngCN2.CN2SDUnorderedLearner": "Orange.classification.rules.CN2SDUnorderedLearner",
276#           "orngCN2.avg": "Orange.classification.rules.avg",
277#           "orngCN2.var": "Orange.classification.rules.var",
278#           "orngCN2.median": "Orange.classification.rules.median",
279#           "orngCN2.perc": "Orange.classification.rules.perc",
280#           "orngCN2.createRandomDataSet": "Orange.classification.rules.createRandomDataSet",
281#           "orngCN2.compParameters": "Orange.classification.rules.compParameters",
282#           "orngCN2.computeDists": "Orange.classification.rules.computeDists",
283#           "orngCN2.createEVDistList": "Orange.classification.rules.createEVDistList",
284           "orngCN2.CovererAndRemover_Prob": "Orange.classification.rules.CovererAndRemover_Prob",
285           "orngCN2.add_sub_rules": "Orange.classification.rules.add_sub_rules",
286           "orngCN2.CN2EVCUnorderedLearner": "Orange.classification.rules.CN2EVCUnorderedLearner",
287
288           "orngMDS.KruskalStress": "Orange.projection.mds.KruskalStress",
289           "orngMDS.SammonStress": "Orange.projection.mds.SammonStress",
290           "orngMDS.SgnSammonStress": "Orange.projection.mds.SgnSammonStress",
291           "orngMDS.SgnRelStress": "Orange.projection.mds.SgnRelStress",
292           "orngMDS.PointList": "Orange.projection.mds.PointList",
293           "orngMDS.FloatListList": "Orange.projection.mds.FloatListList",
294           "orngMDS.PivotMDS": "Orange.projection.mds.PivotMDS",
295           "orngMDS.MDS": "Orange.projection.mds.MDS",
296
297           "orngStat.AP" : "Orange.evaluation.scoring.AP",
298           "orngStat.AROC" : "Orange.evaluation.scoring.AROC",
299           "orngStat.AROCFromCDT" : "Orange.evaluation.scoring.AROC_from_CDT",
300           "orngStat.AUC" : "Orange.evaluation.scoring.AUC",
301           "orngStat.AUCWilcoxon" : "Orange.evaluation.scoring.AUCWilcoxon",
302           "orngStat.AUC_binary" : "Orange.evaluation.scoring.AUC_binary",
303           "orngStat.AUC_i" : "Orange.evaluation.scoring.AUC_i",
304           "orngStat.AUC_ij" : "Orange.evaluation.scoring.AUC_ij",
305           "orngStat.AUC_iterations" : "Orange.evaluation.scoring.AUC_iterations",
306           "orngStat.AUC_matrix" : "Orange.evaluation.scoring.AUC_matrix",
307           "orngStat.AUC_multi" : "Orange.evaluation.scoring.AUC_multi",
308           "orngStat.AUC_pair" : "Orange.evaluation.scoring.AUC_pair",
309           "orngStat.AUC_single" : "Orange.evaluation.scoring.AUC_single",
310           "orngStat.AUC_x" : "Orange.evaluation.scoring.AUC_x",
311           "orngStat.BSS" : "Orange.evaluation.scoring.BSS",
312           "orngStat.BrierScore" : "Orange.evaluation.scoring.Brier_score",
313           "orngStat.CA" : "Orange.evaluation.scoring.CA",
314           "orngStat.CA_se" : "Orange.evaluation.scoring.CA_se",
315           "orngStat.CDT" : "Orange.evaluation.scoring.CDT",
316           "orngStat.ConfusionMatrix" : "Orange.evaluation.scoring.ConfusionMatrix",
317           "orngStat.F1" : "Orange.evaluation.scoring.F1",
318           "orngStat.Falpha" : "Orange.evaluation.scoring.Falpha",
319           "orngStat.Friedman" : "Orange.evaluation.scoring.Friedman",
320           "orngStat.IS" : "Orange.evaluation.scoring.IS",
321           "orngStat.IS_ex" : "Orange.evaluation.scoring.IS_ex",
322           "orngStat.MAE" : "Orange.evaluation.scoring.MAE",
323           "orngStat.MCC" : "Orange.evaluation.scoring.MCC",
324           "orngStat.ME" : "Orange.evaluation.scoring.ME",
325           "orngStat.MSE" : "Orange.evaluation.scoring.MSE",
326           "orngStat.MSE_old" : "Orange.evaluation.scoring.MSE_old",
327           "orngStat.McNemar" : "Orange.evaluation.scoring.McNemar",
328           "orngStat.McNemarOfTwo" : "Orange.evaluation.scoring.McNemar_of_two",
329           "orngStat.NPV" : "Orange.evaluation.scoring.NPV",
330           "orngStat.PPV" : "Orange.evaluation.scoring.PPV",
331           "orngStat.R2" : "Orange.evaluation.scoring.R2",
332           "orngStat.RAE" : "Orange.evaluation.scoring.RAE",
333           "orngStat.RMSE" : "Orange.evaluation.scoring.RMSE",
334           "orngStat.RMSE_old" : "Orange.evaluation.scoring.RMSE_old",
335           "orngStat.ROCaddPoint" : "Orange.evaluation.scoring.ROC_add_point",
336           "orngStat.ROCsFromCDT" : "Orange.evaluation.scoring.ROCs_from_CDT",
337           "orngStat.ROCslope" : "Orange.evaluation.scoring.ROC_slope",
338           "orngStat.RRSE" : "Orange.evaluation.scoring.RRSE",
339           "orngStat.RSE" : "Orange.evaluation.scoring.RSE",
340           "orngStat.TCbestThresholdsOnROCcurve" : "Orange.evaluation.scoring.TC_best_thresholds_on_ROC_curve",
341           "orngStat.TCcomputeROC" : "Orange.evaluation.scoring.TC_compute_ROC",
342           "orngStat.TCthresholdlAverageROC" : "Orange.evaluation.scoring.TC_threshold_average_ROC",
343           "orngStat.TCverticalAverageROC" : "Orange.evaluation.scoring.TC_vertical_average_ROC",
344           "orngStat.Wilcoxon" : "Orange.evaluation.scoring.Wilcoxon",
345           "orngStat.WilcoxonPairs" : "Orange.evaluation.scoring.Wilcoxon_pairs",
346#           "orngStat.add" : "Orange.evaluation.scoring.add",
347#           "orngStat.checkArgkw" : "Orange.evaluation.scoring.checkArgkw",
348#           "orngStat.checkNonZero" : "Orange.evaluation.scoring.checkNonZero",
349           "orngStat.classProbabilitiesFromRes" : "Orange.evaluation.scoring.class_probabilities_from_res",
350           "orngStat.compare2AROCs" : "Orange.evaluation.scoring.compare_2_AROCs",
351           "orngStat.compare2AUCs" : "Orange.evaluation.scoring.compare_2_AUCs",
352           "orngStat.computeCDT" : "Orange.evaluation.scoring.compute_CDT",
353           "orngStat.computeCalibrationCurve" : "Orange.evaluation.scoring.compute_calibration_curve",
354           "orngStat.computeConfusionMatrices" : "Orange.evaluation.scoring.compute_confusion_matrices",
355           "orngStat.computeLiftCurve" : "Orange.evaluation.scoring.compute_lift_curve",
356           "orngStat.computeROC" : "Orange.evaluation.scoring.compute_ROC",
357           "orngStat.compute_CD" : "Orange.evaluation.scoring.compute_CD",
358           "orngStat.compute_friedman" : "Orange.evaluation.scoring.compute_friedman",
359           "orngStat.confusionChiSquare" : "Orange.evaluation.scoring.confusion_chi_square",
360           "orngStat.confusionMatrices" : "Orange.evaluation.scoring.confusion_matrices",
361           "orngStat.defaultLineTypes" : "Orange.evaluation.scoring.default_line_types",
362           "orngStat.defaultPointTypes" : "Orange.evaluation.scoring.default_point_types",
363#           "orngStat.frange" : "Orange.evaluation.scoring.frange",
364#           "orngStat.gettotsize" : "Orange.evaluation.scoring.gettotsize",
365#           "orngStat.gettotweight" : "Orange.evaluation.scoring.gettotweight",
366           "orngStat.graph_ranks" : "Orange.evaluation.scoring.graph_ranks",
367           "orngStat.isCDTEmpty" : "Orange.evaluation.scoring.is_CDT_empty",
368           "orngStat.learningCurve2PiCTeX" : "Orange.evaluation.scoring.learning_curve_to_PiCTeX",
369           "orngStat.learningCurveLearners2PiCTeX" : "Orange.evaluation.scoring.learning_curve_learners_to_PiCTeX",
370           "orngStat.legend2PiCTeX" : "Orange.evaluation.scoring.legend_to_PiCTeX",
371           "orngStat.legendLearners2PiCTeX" : "Orange.evaluation.scoring.legend_learners_to_PiCTeX",
372#           "orngStat.log2" : "Orange.evaluation.scoring.log2",
373#           "orngStat.math" : "Orange.evaluation.scoring.math",
374#           "orngStat.numpy" : "Orange.evaluation.scoring.numpy",
375#           "orngStat.operator" : "Orange.evaluation.scoring.operator",
376           "orngStat.plotLearningCurve" : "Orange.evaluation.scoring.plot_learning_curve",
377           "orngStat.plotLearningCurveLearners" : "Orange.evaluation.scoring.plot_learning_curve_learners",
378           "orngStat.plotMcNemarCurve" : "Orange.evaluation.scoring.plot_McNemar_curve",
379           "orngStat.plotMcNemarCurveLearners" : "Orange.evaluation.scoring.plot_McNemar_curve_learners",
380           "orngStat.plotROC" : "Orange.evaluation.scoring.plot_ROC",
381           "orngStat.plotROCLearners" : "Orange.evaluation.scoring.plot_ROC_learners",
382           "orngStat.precision" : "Orange.evaluation.scoring.precision",
383           "orngStat.printSingleROCCurveCoordinates" : "Orange.evaluation.scoring.print_single_ROC_curve_coordinates",
384           "orngStat.rankDifference" : "Orange.evaluation.scoring.rank_difference",
385           "orngStat.recall" : "Orange.evaluation.scoring.recall",
386           "orngStat.regressionError" : "Orange.evaluation.scoring.regression_error",
387           "orngStat.scottsPi" : "Orange.evaluation.scoring.scotts_pi",
388           "orngStat.sens" : "Orange.evaluation.scoring.sens",
389           "orngStat.spec" : "Orange.evaluation.scoring.spec",
390           "orngStat.splitByIterations" : "Orange.evaluation.scoring.split_by_iterations",
391#           "orngStat.statc" : "Orange.evaluation.scoring.statc",
392           "orngStat.statisticsByFolds" : "Orange.evaluation.scoring.statistics_by_folds",
393#           "orngStat.x" : "Orange.evaluation.scoring.x",
394
395           # Orange.selection
396           "orngMisc.BestOnTheFly":"Orange.misc.selection.BestOnTheFly",
397           "orngMisc.selectBest":"Orange.misc.selection.select_best",
398           "orngMisc.selectBestIndex":"Orange.misc.selection.select_best_index",
399           "orngMisc.compare2_firstBigger":"Orange.misc.selection.compare_first_bigger",
400           "orngMisc.compare2_firstSmaller":"Orange.misc.selection.compare_first_smaller",
401           "orngMisc.compare2_lastBigger":"Orange.misc.selection.compare_last_bigger",
402           "orngMisc.compare2_lastSmaller":"Orange.misc.selection.compare_last_smaller",
403           "orngMisc.compare2_bigger":"Orange.misc.selection.compare_bigger",
404           "orngMisc.compare2_smaller":"Orange.misc.selection.compare_smaller",
405
406           "orngMisc.Renderer": "Orange.misc.render.Renderer",
407           "orngMisc.EPSRenderer": "Orange.misc.render.EPSRenderer",
408           "orngMisc.SVGRenderer": "Orange.misc.render.SVGRenderer",
409           "orngMisc.PILRenderer": "Orange.misc.render.PILRenderer",
410           # The rest of orngMisc is handled by fix_orange_imports (maps to Orange.misc)
411
412           "orngEnsemble.BaggedLearner":"Orange.ensemble.bagging.BaggedLearner",
413           "orngEnsemble.BaggedClassifier":"Orange.ensemble.bagging.BaggedClassifier",
414           "orngEnsemble.BoostedLearner":"Orange.ensemble.boosting.BoostedLearner",
415           "orngEnsemble.BoostedClassifier":"Orange.ensemble.boosting.BoostedClassifier",
416           "orngEnsemble.RandomForestClassifier":"Orange.ensemble.forest.RandomForestClassifier",
417           "orngEnsemble.RandomForestLearner":"Orange.ensemble.forest.RandomForestLearner",
418           "orngEnsemble.MeasureAttribute_randomForests":"Orange.ensemble.forest.ScoreFeature",
419           "orngEnsemble.SplitConstructor_AttributeSubset":"Orange.ensemble.forest.SplitConstructor_AttributeSubset",
420
421           "orngTest.proportionTest":"Orange.evaluation.testing.proportion_test",
422           "orngTest.leaveOneOut":"Orange.evaluation.testing.leave_one_out",
423           "orngTest.crossValidation":"Orange.evaluation.testing.cross_validation",
424           "orngTest.testWithIndices":"Orange.evaluation.testing.test_with_indices",
425           "orngTest.learningCurve":"Orange.evaluation.testing.learning_curve",
426           "orngTest.learningCurveN":"Orange.evaluation.testing.learning_curve_n",
427           "orngTest.learningCurveWithTestData":"Orange.evaluation.testing.learning_curve_with_test_data",
428           "orngTest.learnAndTestOnTestData":"Orange.evaluation.testing.learn_and_test_on_test_data",
429           "orngTest.learnAndTestOnLearnData":"Orange.evaluation.testing.learn_and_test_on_learn_data",
430           "orngTest.testOnData":"Orange.evaluation.testing.test_on_data",
431           "orngTest.TestedExample":"Orange.evaluation.testing.TestedExample",
432           "orngTest.ExperimentResults":"Orange.evaluation.testing.ExperimentResults",
433
434           "orngLR.dump":"Orange.classification.logreg.dump",
435           "orngLR.printOUT":"Orange.classification.logreg.dump",
436           "orngLR.printOut":"Orange.classification.logreg.dump",
437           "orngLR.hasDiscreteValues":"Orange.classification.logreg.has_discrete_values",
438           "orngLR.LogRegLearner":"Orange.classification.logreg.LogRegLearner",
439           "orngLR.LogRegLearnerClass":"Orange.classification.logreg.LogRegLearner",
440           "orngLR.Univariate_LogRegLearner":"Orange.classification.logreg.UnivariateLogRegLearner",
441           "orngLR.Univariate_LogRegLearner_Class":"Orange.classification.logreg.UnivariateLogRegLearner",
442           "orngLR.Univariate_LogRegClassifier":"Orange.classification.logreg.UnivariateLogRegClassifier",
443           "orngLR.LogRegLearner_getPriors":"Orange.classification.logreg.LogRegLearnerGetPriors",
444           "orngLR.LogRegLearnerClass_getPriors":"Orange.classification.logreg.LogRegLearnerGetPriors",
445           "orngLR.LogRegLearnerClass_getPriors_OneTable":"Orange.classification.logreg.LogRegLearnerGetPriorsOneTable",
446           "orngLR.Pr":"Orange.classification.logreg.pr",
447           "orngLR.lh":"Orange.classification.logreg.lh",
448           "orngLR.diag":"Orange.classification.logreg.diag",
449           "orngLR.simpleFitter":"Orange.classification.logreg.SimpleFitter",
450           "orngLR.Pr_bx":"Orange.classification.logreg.pr_bx",
451           "orngLR.bayesianFitter":"Orange.classification.logreg.BayesianFitter",
452           "orngLR.StepWiseFSS":"Orange.classification.logreg.StepWiseFSS",
453           "orngLR.getLikelihood":"Orange.classification.logreg.get_likelihood",
454           "orngLR.StepWiseFSS_class":"Orange.classification.logreg.StepWiseFSS",
455           "orngLR.StepWiseFSS_Filter":"Orange.classification.logreg.StepWiseFSSFilter",
456           "orngLR.StepWiseFSS_Filter_class":"Orange.classification.logreg.StepWiseFSSFilter",
457           "orngLR.lchisqprob":"Orange.classification.logreg.lchisqprob",
458           "orngLR.zprob":"Orange.classification.logreg.zprob",
459
460           "orange.Preprocessor": "Orange.preprocess.Preprocessor",
461           "orange.Preprocessor_addCensorWeight": "Orange.preprocess.Preprocessor_addCensorWeight",
462           "orange.Preprocessor_addClassNoise": "Orange.preprocess.Preprocessor_addClassNoise",
463           "orange.Preprocessor_addClassWeight": "Orange.preprocess.Preprocessor_addClassWeight",
464           "orange.Preprocessor_addGaussianClassNoise": "Orange.preprocess.Preprocessor_addGaussianClassNoise",
465           "orange.Preprocessor_addGaussianNoise": "Orange.preprocess.Preprocessor_addGaussianNoise",
466           "orange.Preprocessor_addMissing": "Orange.preprocess.Preprocessor_addMissing",
467           "orange.Preprocessor_addMissingClasses": "Orange.preprocess.Preprocessor_addMissingClasses",
468           "orange.Preprocessor_addNoise": "Orange.preprocess.Preprocessor_addNoise",
469           "orange.Preprocessor_discretize": "Orange.preprocess.Preprocessor_discretize",
470           "orange.Preprocessor_drop": "Orange.preprocess.Preprocessor_drop",
471           "orange.Preprocessor_dropMissing": "Orange.preprocess.Preprocessor_dropMissing",
472           "orange.Preprocessor_dropMissingClasses": "Orange.preprocess.Preprocessor_dropMissingClasses",
473           "orange.Preprocessor_filter": "Orange.preprocess.Preprocessor_filter",
474           "orange.Preprocessor_ignore": "Orange.preprocess.Preprocessor_ignore",
475           "orange.Preprocessor_imputeByLearner": "Orange.preprocess.Preprocessor_imputeByLearner",
476           "orange.Preprocessor_removeDuplicates": "Orange.preprocess.Preprocessor_removeDuplicates",
477           "orange.Preprocessor_select": "Orange.preprocess.Preprocessor_select",
478           "orange.Preprocessor_shuffle": "Orange.preprocess.Preprocessor_shuffle",
479           "orange.Preprocessor_take": "Orange.preprocess.Preprocessor_take",
480           "orange.Preprocessor_takeMissing": "Orange.preprocess.Preprocessor_takeMissing",
481           "orange.Preprocessor_takeMissingClasses": "Orange.preprocess.Preprocessor_takeMissingClasses",
482
483           "orange.Discretizer": "Orange.feature.discretization.Discretizer",
484           "orange.BiModalDiscretizer": "Orange.feature.discretization.BiModalDiscretizer",
485           "orange.EquiDistDiscretizer": "Orange.feature.discretization.EquiDistDiscretizer",
486           "orange.IntervalDiscretizer": "Orange.feature.discretization.IntervalDiscretizer",
487           "orange.ThresholdDiscretizer": "Orange.feature.discretization.ThresholdDiscretizer",
488           "orange.Discrete2Continuous": "Orange.feature.discretization.Discrete2Continuous",
489
490           "orange.DomainContinuizer": "Orange.feature.continuization.DomainContinuizer",
491
492           "orange.MakeRandomIndices": "Orange.data.sample.SubsetIndices",
493           "orange.MakeRandomIndicesN": "Orange.data.sample.SubsetIndicesN",
494           "orange.MakeRandomIndicesCV": "Orange.data.sample.SubsetIndicesCV",
495           "orange.MakeRandomIndicesMultiple": "Orange.data.sample.SubsetIndicesMultiple",
496           "orange.MakeRandomIndices2": "Orange.data.sample.SubsetIndices2",
497
498           "orngLinProj.FAST_IMPLEMENTATION": "Orange.projection.linear.FAST_IMPLEMENTATION",
499           "orngLinProj.SLOW_IMPLEMENTATION": "Orange.projection.linear.SLOW_IMPLEMENTATION",
500           "orngLinProj.LDA_IMPLEMENTATION": "Orange.projection.linear.LDA_IMPLEMENTATION",
501           "orngLinProj.LAW_LINEAR": "Orange.projection.linear.LAW_LINEAR",
502           "orngLinProj.LAW_SQUARE": "Orange.projection.linear.LAW_SQUARE",
503           "orngLinProj.LAW_GAUSSIAN": "Orange.projection.linear.LAW_GAUSSIAN",
504           "orngLinProj.LAW_KNN": "Orange.projection.linear.LAW_KNN",
505           "orngLinProj.LAW_LINEAR_PLUS": "Orange.projection.linear.LAW_LINEAR_PLUS",
506           "orngLinProj.DR_PCA": "Orange.projection.linear.DR_PCA",
507           "orngLinProj.DR_SPCA": "Orange.projection.linear.DR_SPCA",
508           "orngLinProj.DR_PLS": "Orange.projection.linear.DR_PLS",
509           "orngLinProj.normalize": "Orange.projection.linear.normalize",
510           "orngLinProj.center": "Orange.projection.linear.center",
511           "orngLinProj.FreeViz": "Orange.projection.linear.FreeViz",
512           "orngLinProj.createPLSProjection": "Orange.projection.linear.create_pls_projection",
513           "orngLinProj.createPCAProjection": "Orange.projection.linear.create_pca_projection",
514           "orngLinProj.FreeVizClassifier": "Orange.projection.linear.FreeVizClassifier",
515           "orngLinProj.FreeVizLearner": "Orange.projection.linear.FreeVizLearner",
516           "orngLinProj.S2NHeuristicLearner": "Orange.projection.linear.S2NHeuristicLearner",
517
518           "orngDisc.entropyDiscretization": "Orange.feature.discretization.entropyDiscretization_wrapper",
519           "orngDisc.EntropyDiscretization": "Orange.feature.discretization.EntropyDiscretization_wrapper",
520
521           "orange.ProbabilityEstimatorList": "Orange.statistics.estimate.ProbabilityEstimatorList",
522
523           "orange.FilterList": "Orange.preprocess.FilterList",
524           "orange.Filter": "Orange.preprocess.Filter",
525           "orange.Filter_conjunction": "Orange.preprocess.Filter_conjunction",
526           "orange.Filter_disjunction": "Orange.preprocess.Filter_disjunction",
527           "orange.Filter_hasClassValue": "Orange.preprocess.Filter_hasClassValue",
528           "orange.Filter_hasMeta": "Orange.preprocess.Filter_hasMeta",
529           "orange.Filter_hasSpecial": "Orange.preprocess.Filter_hasSpecial",
530           "orange.Filter_isDefined": "Orange.preprocess.Filter_isDefined",
531           "orange.Filter_random": "Orange.preprocess.Filter_random",
532           "orange.Filter_sameValue": "Orange.preprocess.Filter_sameValue",
533           "orange.Filter_values": "Orange.preprocess.Filter_values",
534
535           # orngEnviron
536
537           "orngEnviron.orangeDir": "Orange.misc.environ.install_dir",
538           "orngEnviron.orangeDocDir": "Orange.misc.environ.doc_install_dir",
539           "orngEnviron.orangeVer": "Orange.misc.environ.version",
540           "orngEnviron.canvasDir": "Orange.misc.environ.canvas_install_dir",
541           "orngEnviron.widgetDir": "Orange.misc.environ.widget_install_dir",
542           "orngEnviron.picsDir": "Orange.misc.environ.icons_install_dir",
543           "orngEnviron.addOnsDirSys": "Orange.misc.environ.add_ons_dir",
544           "orngEnviron.addOnsDirUser": "Orange.misc.environ.add_ons_dir_user",
545           "orngEnviron.applicationDir": "Orange.misc.environ.application_dir",
546           "orngEnviron.outputDir": "Orange.misc.environ.output_dir",
547           "orngEnviron.defaultReportsDir": "Orange.misc.environ.default_reports_dir",
548           "orngEnviron.orangeSettingsDir": "Orange.misc.environ.orange_settings_dir",
549           "orngEnviron.widgetSettingsDir": "Orange.misc.environ.widget_settings_dir",
550           "orngEnviron.canvasSettingsDir": "Orange.misc.environ.canvas_settings_dir",
551           "orngEnviron.bufferDir": "Orange.misc.environ.buffer_dir",
552           "orngEnviron.directoryNames": "Orange.misc.environ.directories",
553           "orngEnviron.samepath": "Orange.misc.environ.samepath",
554           "orngEnviron.addOrangeDirectoriesToPath": "Orange.misc.environ.add_orange_directories_to_path",
555
556           "orngScaleData.getVariableValuesSorted": "Orange.preprocess.scaling.get_variable_values_sorted",
557           "orngScaleData.getVariableValueIndices": "Orange.preprocess.scaling.get_variable_value_indices",
558           "orngScaleData.discretizeDomain": "Orange.preprocess.scaling.discretize_domain",
559           "orngScaleData.orngScaleData": "Orange.preprocess.scaling.ScaleData",
560           "orngScaleLinProjData.orngScaleLinProjData": "Orange.preprocess.scaling.ScaleLinProjData",
561           "orngScalePolyvizData.orngScalePolyvizData": "Orange.preprocess.scaling.ScalePolyvizData",
562           "orngScaleScatterPlotData.orngScaleScatterPlotData": "Orange.preprocess.scaling.ScaleScatterPlotData",
563
564           "orngEvalAttr.mergeAttrValues": "Orange.feature.scoring.merge_values",
565           "orngEvalAttr.MeasureAttribute_MDL": "Orange.feature.scoring.MDL",
566           "orngEvalAttr.MeasureAttribute_MDLClass": "Orange.feature.scoring.MDL",
567           "orngEvalAttr.MeasureAttribute_Distance": "Orange.feature.scoring.Distance",
568           "orngEvalAttr.MeasureAttribute_DistanceClass": "Orange.feature.scoring.Distance",
569           "orngEvalAttr.OrderAttributesByMeasure": "Orange.feature.scoring.OrderAttributes",
570
571           "orange.ProbabilityEstimator": "Orange.statistics.estimate.Estimator",
572           "orange.ProbabilityEstimator_FromDistribution": "Orange.statistics.estimate.EstimatorFromDistribution",
573           "orange.ProbabilityEstimatorConstructor": "Orange.statistics.estimate.EstimatorConstructor",
574           "orange.ProbabilityEstimatorConstructor_Laplace": "Orange.statistics.estimate.Laplace",
575           "orange.ProbabilityEstimatorConstructor_kernel": "Orange.statistics.estimate.Kernel",
576           "orange.ProbabilityEstimatorConstructor_loess": "Orange.statistics.estimate.Loess",
577           "orange.ProbabilityEstimatorConstructor_m": "Orange.statistics.estimate.M",
578           "orange.ProbabilityEstimatorConstructor_relative": "Orange.statistics.estimate.RelativeFrequency",
579           "orange.ConditionalProbabilityEstimator": "Orange.statistics.estimate.ConditionalEstimator",
580           "orange.ConditionalProbabilityEstimator_FromDistribution": "Orange.statistics.estimate.ConditionalEstimatorFromDistribution",
581           "orange.ConditionalProbabilityEstimator_ByRows": "Orange.statistics.estimate.ConditionalEstimatorByRows",
582           "orange.ConditionalProbabilityEstimatorConstructor_ByRows": "Orange.statistics.estimate.ConditionalByRows",
583           "orange.ConditionalProbabilityEstimatorConstructor_loess": "Orange.statistics.estimate.ConditionalLoess",
584
585           "orange.RandomGenerator": "Orange.misc.Random",
586
587           }
588
589def build_pattern(mapping=MAPPING):
590    PATTERN = """
591    power< head=any+
592         trailer< '.' member=(%s) >
593         tail=any*
594    >
595    """
596    return PATTERN % "|".join("'%s'" % key.split(".")[-1] for key in mapping.keys())
597
598class FixChangedNames(fixer_base.BaseFix):
599    mapping = MAPPING
600
601    run_order = 1
602
603    def compile_pattern(self):
604        self.PATTERN = build_pattern(self.mapping)
605        self._modules_to_change = [key.split(".", 1)[0] for key in self.mapping.keys()]
606        super(FixChangedNames, self).compile_pattern()
607
608    def package_tree(self, package):
609        """ Return pytree tree for accessing the package
610       
611        Example:
612            >>> package_tree("Orange.feature.scoring")
613            [Name('Orange'), trailer('.' 'feature'), trailer('.', 'scoring')]
614        """
615        path = package.split('.')
616        nodes = [Name(path[0])]
617        for name in path[1:]:
618            new = pytree.Node(self.syms.trailer, [Dot(), Name(name)])
619            nodes.append(new)
620        return nodes
621
622
623    def transform(self, node, results):
624        member = results.get("member")
625        head = results.get("head")
626        tail = results.get("tail")
627        module = head[0].value
628
629        if member and module in self._modules_to_change:
630            node = member[0]
631            head = head[0]
632
633            old_name = module + "." + node.value
634            if old_name not in self.mapping:
635                return
636
637            new_name = unicode(self.mapping[old_name])
638
639            if ":" in new_name:
640                # ':' is the delimiter used to separate module namespace
641                package = new_name.split(":", 1)[0]
642                new_name = new_name.replace(":", ".")
643            else:
644                package = new_name.rsplit(".", 1)[0]
645
646            syms = self.syms
647
648            if tail:
649                tail = [t.clone() for t in  tail]
650            new = self.package_tree(new_name)
651            new = pytree.Node(syms.power, new + tail, prefix=head.prefix)
652
653            # Make sure the proper package is imported
654#            if ":" in new_name:
655#                package = new_name.split(":",1)[0]
656#            else:
657#                package = new_name.rsplit(".", 1)[0]
658
659            def orange_to_root(package):
660                return "Orange" if package.startswith("Orange.") else package
661
662            touch_import(None, orange_to_root(package), node)
663            return new
664
Note: See TracBrowser for help on using the repository browser.