K*********n 发帖数: 2852 | 1 Scala纯新手,写了点测试代码:
###### build.sbt #########
name := "Train NB"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "1.2.0",
"commons-io" % "commons-io" % "2.4",
"com.google.code.gson" % "gson" % "2.2.4",
"org.la4j" % "la4j" % "0.4.9"
)
javacOptions ++= Seq("-source", "1.7", "-target", "1.7")
####### scala code ##########
package app.mycompany
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import app.mycompany.DataPrepSpark
object TrainModels {
def runTraining(input: String, output: String) = {
val conf = new SparkConf().setAppName("Naive Bayes with Spark")
val sc = new SparkContext(conf)
val rawData = sc.textFile(input)
val groupedData = rawData groupBy { G =>
G.split("t")(0)
}
val models = groupedData map { G =>
DataPrepSpark.processData(G._1, G._2.toArra, 5)
}
models.saveAsTextFile(output)
}
def main(args: Array[String]) = {
runTraining(args(0), args(1))
}
}
######## java code ######
package app.mycompany;
import com.google.gson.*;
import org.apache.commons.io.FileUtils;
import org.la4j.io.MatrixMarketStream;
import org.la4j.matrix.Matrix;
import org.la4j.matrix.sparse.CCSMatrix;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test
{
public static String processData(String id, String[] rows, int length)
{
System.out.println("TESTING....................");
System.out.println(length);
return id;
}
}
java和scala代码都在一个package里面,所用的jar的build path也都检查过了。然后:
$sbt package
告诉我: "object Test is not a member of package app.mycompany"...
无头绪。多谢! |
|