Skip to content

Commit 3d27555

Browse files
committed
Some progress towards autogenerating the lucene analyzer stages but not quite there yet.
1 parent ab59343 commit 3d27555

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ libraryDependencies ++= Seq(
3636
"com.lucidworks.spark" % "spark-solr" % "3.0.2",
3737
// internals
3838
"org.scala-lang" % "scala-reflect" % "2.11.7",
39+
"org.reflections" % "reflections" % "0.9.11",
3940
// testing libraries
4041
"org.scalatest" %% "scalatest" % "3.0.1",
4142
"org.scalacheck" %% "scalacheck" % "1.13.4",

src/main/scala/com/sparklingpandas/sparklingml/feature/LuceneAnalyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sparklingpandas.sparklingml
1+
package com.sparklingpandas.sparklingml.feature
22

33
import org.apache.spark.annotation.DeveloperApi
44
import org.apache.spark.ml.UnaryTransformer
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.sparklingpandas.sparklingml.feature
2+
3+
import org.apache.spark.annotation.DeveloperApi
4+
5+
import org.apache.lucene.analysis.Analyzer
6+
7+
@DeveloperApi
8+
object LuceneAnalyzerGenerators {
9+
def generate() = {
10+
import org.reflections.Reflections
11+
import collection.JavaConverters._
12+
import scala.reflect.runtime.universe._
13+
val reflections = new Reflections("org.apache.lucene");
14+
val analyzers = reflections.getSubTypesOf(classOf[org.apache.lucene.analysis.Analyzer])
15+
val rm = scala.reflect.runtime.currentMirror
16+
val generated = analyzers.asScala.map{ cls =>
17+
val constructors = rm.classSymbol(cls).toType.members.collect{
18+
case m: MethodSymbol if m.isConstructor && m.isPublic => m }
19+
// Since this isn't built with -parameters by default :(
20+
// we'd need a local version built with it to auto generate
21+
// the code here with the right parameters.
22+
// https://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html
23+
// For now we could dump the class names and go from their
24+
// or we could play a game of pin the field on the constructor.
25+
// local build sounds like the best plan, lets do that l8r
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)