databricks / spark-corenlp

Stanford CoreNLP wrapper for Apache Spark
GNU General Public License v3.0
422 stars 120 forks source link

How to use this lib in java #33

Open LinRick opened 6 years ago

LinRick commented 6 years ago

Hi all, Would you tell me how to use this lib in java? I can import it, but i do not know to use. "import com.databricks.spark.corenlp.functions;" The maven project pom.xml:

databricks spark-corenlp 0.2.0-s_2.11

In the following, there is my program. SparkSession spark = SparkSession.builder().getOrCreate(); JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
StructField[] structFields = new StructField[]{ new StructField("intColumn", DataTypes.IntegerType, true, Metadata.empty()), new StructField("stringColumn", DataTypes.StringType, true, Metadata.empty()) };

StructType structType = new StructType(structFields);

List rows = new ArrayList<>(); rows.add(RowFactory.create(1, "Stanford University is located in California. " + "It is a great university."));

Dataset df = spark.createDataFrame(rows, structType);

System.out.println("Test Count = " + df.count());

df.show();

Rick