Subversion Repositories SmartDukaan

Rev

Rev 65 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 65 Rev 70
Line 13... Line 13...
13
 
13
 
14
import java.util.List;
14
import java.util.List;
15
 
15
 
16
import org.python.core.PyList;
16
import org.python.core.PyList;
17
import org.python.core.PyObject;
17
import org.python.core.PyObject;
18
import org.python.util.PythonInterpreter;
-
 
19
 
18
 
20
/**
19
/**
-
 
20
 * Wrapper around Jython for Information Retrieval Python scripts
-
 
21
 * 
21
 * @author naveen
22
 * @author naveen
22
 *
23
 *
23
 */
24
 */
24
public class JythonWrapper {
25
public class IRJythonWrapper extends JythonWrapper {
25
	
-
 
26
	/**
-
 
27
	 * Private Python interpreter instance
-
 
28
	 */
-
 
29
	private PythonInterpreter py = null;
-
 
30
	
26
	
31
	/**
27
	/**
32
	 * Local instance of Facet Definition - Used to pick script to execute
28
	 * Local instance of Facet Definition - Used to pick script to execute
33
	 */
29
	 */
34
	private ExpandedFacetDefinition expandedFacetDefinition = null;
30
	private ExpandedFacetDefinition expandedFacetDefinition = null;
35
	
31
	
36
	/**
32
	/**
37
	 * Resets current PythonInterpreter instance
33
	 * Resets current PythonInterpreter instance
38
	 */
34
	 */
39
	public void initialize() {
35
	public void reset() {
40
		this.py = null;
36
		super.reset();
41
		this.expandedFacetDefinition = null;
37
		this.expandedFacetDefinition = null;
42
	}
38
	}
43
	
39
	
44
	/**
40
	/**
45
	 * 
41
	 * 
46
	 * @param expandedFacetDefinition
42
	 * @param expandedFacetDefinition
47
	 */
43
	 */
48
	public void setExpandedFacetDefinition(
44
	public void setExpandedFacetDefinition(
49
			ExpandedFacetDefinition expandedFacetDefinition) {
45
			ExpandedFacetDefinition expandedFacetDefinition) {
50
		if(this.py == null) {
46
		this.initialize();
51
			this.py = new PythonInterpreter();
-
 
52
		}
-
 
53
		
47
		
54
		this.expandedFacetDefinition = expandedFacetDefinition;
48
		this.expandedFacetDefinition = expandedFacetDefinition;
55
		this.py.set("expFacetDef", expandedFacetDefinition);
49
		this.py.set("expFacetDef", expandedFacetDefinition);
56
	}
50
	}
57
	
51
	
58
	/**
52
	/**
59
	 * 
53
	 * 
60
	 * @param entity
54
	 * @param entity
61
	 */
55
	 */
62
	public void setExpandedEntity(ExpandedEntity expEntity) {
56
	public void setExpandedEntity(ExpandedEntity expEntity) {
63
		if(this.py == null) {
57
		this.initialize();
64
			this.py = new PythonInterpreter();
-
 
65
		}
-
 
66
		
58
		
67
		this.py.set("expEntity", expEntity);
59
		this.py.set("expEntity", expEntity);
68
	}
60
	}
69
	
61
	
70
	/**
62
	/**
71
	 * 
63
	 * 
72
	 * @param featureDefinition
64
	 * @param featureDefinition
73
	 */
65
	 */
74
	public void setFeatureDefinition(FeatureDefinition featureDefinition) {
66
	public void setFeatureDefinition(FeatureDefinition featureDefinition) {
75
		if(this.py == null) {
67
		this.initialize();
76
			this.py = new PythonInterpreter();
-
 
77
		}
-
 
78
		
68
		
79
		this.py.set("featureDef", featureDefinition);
69
		this.py.set("featureDef", featureDefinition);
80
	}
70
	}
81
	
71
	
82
	/**
72
	/**
83
	 * 
73
	 * 
84
	 * @param feature
74
	 * @param feature
85
	 */
75
	 */
86
	public void setExpandedFeature(ExpandedFeature expandedFeature) {
76
	public void setExpandedFeature(ExpandedFeature expandedFeature) {
87
		if(this.py == null) {
77
		this.initialize();
88
			this.py = new PythonInterpreter();
-
 
89
		}
-
 
90
		
78
		
91
		this.py.set("expFeature", expandedFeature);
79
		this.py.set("expFeature", expandedFeature);
92
	}
80
	}
93
	
81
	
94
	/**
82
	/**
95
	 * 
83
	 * 
96
	 * @param slideDefinition
84
	 * @param slideDefinition
97
	 */
85
	 */
98
	public void setSlideDefinition(SlideDefinition slideDefinition) {
86
	public void setSlideDefinition(SlideDefinition slideDefinition) {
99
		if(this.py == null) {
87
		this.initialize();
100
			this.py = new PythonInterpreter();
-
 
101
		}
-
 
102
		
88
		
103
		this.py.set("slideDef", slideDefinition);
89
		this.py.set("slideDef", slideDefinition);
104
	}
90
	}
105
	
91
	
106
	/**
92
	/**
107
	 * 
93
	 * 
108
	 * @param slide
94
	 * @param slide
109
	 */
95
	 */
110
	public void setExpandedSlide(ExpandedSlide expSlide) {
96
	public void setExpandedSlide(ExpandedSlide expSlide) {
111
		if(this.py == null) {
97
		this.initialize();
112
			this.py = new PythonInterpreter();
-
 
113
		}
-
 
114
		
98
		
115
		this.py.set("expSlide", expSlide);
99
		this.py.set("expSlide", expSlide);
116
	}
100
	}
117
	
101
	
118
	/**
102
	/**
Line 126... Line 110...
126
		
110
		
127
		RuleDefinition irdataRuleDef = 
111
		RuleDefinition irdataRuleDef = 
128
			this.expandedFacetDefinition.getIrdataRuleDefinition();
112
			this.expandedFacetDefinition.getIrdataRuleDefinition();
129
		
113
		
130
		String pyScript = irdataRuleDef.getScript();
114
		String pyScript = irdataRuleDef.getScript();
131
		String scriptFullPath = IR.JYTHON_SRC_PATH + "irdatarules/" + pyScript;
115
		String scriptFullPath = Utils.JYTHON_SRC_PATH + "irdatarules/" + pyScript;
132
		Utils.info("irdataRuleDef.getID()=" + irdataRuleDef.getID());
116
		Utils.info("irdataRuleDef.getID()=" + irdataRuleDef.getID());
133
		Utils.info("scriptFullPath=" + scriptFullPath);
117
		Utils.info("scriptFullPath=" + scriptFullPath);
134
		
118
		
135
		this.exec(scriptFullPath);
119
		this.exec(scriptFullPath);
136
	}
120
	}
137
	
121
	
138
	/**
122
	/**
139
	 * Executes Jython script given absolute path
-
 
140
	 * 
-
 
141
	 * @param filename
-
 
142
	 */
-
 
143
	public void exec(String filename) {
-
 
144
		if(this.py == null) {
-
 
145
			this.py = new PythonInterpreter();
-
 
146
		}
-
 
147
		
-
 
148
		this.py.execfile(filename);
-
 
149
	}
-
 
150
	
-
 
151
	/**
-
 
152
	 * 
123
	 * 
153
	 * @return
124
	 * @return
154
	 */
125
	 */
155
	@SuppressWarnings("unchecked")
126
	@SuppressWarnings("unchecked")
156
	public List getValues() {
127
	public List getValues() {