本文整理汇总了Scala中scala.collection.mutable.ListBuffer类的典型用法代码示例。如果您正苦于以下问题:Scala ListBuffer类的具体用法?Scala ListBuffer怎么用?Scala ListBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ListBuffer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: HDFS
//设置package包名称以及导入依赖的类
package org.mireynol.util
import java.io.{BufferedInputStream, OutputStreamWriter}
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.{FileSystem, Path}
import org.slf4j.{Logger, LoggerFactory}
import scala.collection.mutable.ListBuffer
import scala.io.Source
object HDFS {
def log : Logger = LoggerFactory.getLogger( HDFS.getClass )
val hadoop : FileSystem = {
val conf = new Configuration( )
conf.set( "fs.defaultFS", "hdfs://localhost:9000" )
FileSystem.get( conf )
}
def readAndMap( path : String, mapper : ( String ) => Unit ) = {
if ( hadoop.exists( new Path( path ) ) ) {
val is = new BufferedInputStream( hadoop.open( new Path( path ) ) )
Source.fromInputStream( is ).getLines( ).foreach( mapper )
}
else {
// TODO - error logic here
}
}
def write( filename : String, content : Iterator[ String ] ) = {
val path = new Path( filename )
val out = new OutputStreamWriter( hadoop.create( path, false ) )
content.foreach( str => out.write( str + "\n" ) )
out.flush( )
out.close( )
}
def ls( path : String ) : List[ String ] = {
val files = hadoop.listFiles( new Path( path ), false )
val filenames = ListBuffer[ String ]( )
while ( files.hasNext ) filenames += files.next( ).getPath( ).toString( )
filenames.toList
}
def rm( path : String, recursive : Boolean ) : Unit = {
if ( hadoop.exists( new Path( path ) ) ) {
println( "deleting file : " + path )
hadoop.delete( new Path( path ), recursive )
}
else {
println( "File/Directory" + path + " does not exist" )
log.warn( "File/Directory" + path + " does not exist" )
}
}
def cat( path : String ) = Source.fromInputStream( hadoop.open( new Path( path ) ) ).getLines( ).foreach( println )
}
开发者ID:reynoldsm88,项目名称:spark-drools,代码行数:61,代码来源:HDFS.scala
示例2: StoryController
//设置package包名称以及导入依赖的类
package controllers
import controllers.StoryModel.StoryData
import javax.inject.Inject
import play.api.Configuration
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import model.StoryDao
import model.DataModel.Story
import scala.collection.mutable.ListBuffer
class StoryController @Inject()(implicit storyDao:StoryDao,config:Configuration) extends Controller{
def index = Action {
val result = storyDao.create();
Ok(views.html.story("Welcome to StoryBoard !!",listStory))
}
def createStory = Action { implicit Request =>
var result = storyDao.insert(new Story(storyForm.bindFromRequest().get.title,storyForm.bindFromRequest().get.description))
Ok(views.html.story("Story Created:" + "(" + storyForm.bindFromRequest().get.title + "," + storyForm.bindFromRequest().get.description + ")",listStory))
}
def listStory:List[StoryData] = {
val stories:List[Story] = storyDao.list
var storiesData = new ListBuffer[StoryData]
for(s <- stories){
storiesData += (new StoryData(s.title,s.description))
}
storiesData.toList
}
val storyForm = Form(
mapping(
"title" -> text,
"description" -> text
)(StoryData.apply)(StoryData.unapply)
)
}
object StoryModel{
case class StoryData(
title:String,
description:String
)
}
开发者ID:rajat965ng,项目名称:storyBoard,代码行数:53,代码来源:StoryController.scala
示例3: Screen
//设置package包名称以及导入依赖的类
package no.vestein.webapp
import no.vestein.webapp.App.Ctx2D
import org.scalajs.dom
import scala.collection.mutable.ListBuffer
import scala.scalajs.js
class Screen(val width: Int, val height: Int, val canvas: dom.html.Canvas, val game: Game) {
type KeyboardEvent = dom.KeyboardEvent
type FocusEvent = dom.FocusEvent
val updateInterval: Double = 16
val keys: ListBuffer[Int] = new ListBuffer[Int]
val ctx: Ctx2D = canvas.getContext("2d").asInstanceOf[Ctx2D]
var active: Boolean = true
var prevTime: Double = js.Date.now()
canvas.tabIndex = 1
canvas.width = width
canvas.height = height
canvas.onkeydown = (e : KeyboardEvent) => if (!keys.contains(e.keyCode)) keys += e.keyCode
canvas.onkeyup = (e: KeyboardEvent) => keys -= e.keyCode
canvas.onfocus = (e: FocusEvent) => active = true
canvas.onblur = (e: FocusEvent) => active = false
def update(): Unit = {
val now = js.Date.now()
if (active) {
val delta = now - prevTime
if (delta > updateInterval) {
game.update(delta, keys.toSet[Int])
game.render(this)
prevTime = now
}
} else {
prevTime = now
}
}
}
开发者ID:WoodStone,项目名称:PurpleRain-ScalaJS,代码行数:45,代码来源:Screen.scala
示例4: InputParsers
//设置package包名称以及导入依赖的类
package tul.poiis.decision_tree
import scala.collection.mutable.ListBuffer
object InputParsers {
def parseMovieEntry(csv_entry: Map[String, String]): (Int, Movie) = {
val fieldsList = ListBuffer[MovieField]()
fieldsList += new PopularityField(csv_entry("popularity"))
fieldsList += new BudgetField(csv_entry("budget"))
fieldsList += new VoteAverageField(csv_entry("vote_average"))
fieldsList += new ReleaseYearField(csv_entry("release_date"))
(csv_entry("Id").toInt, new Movie(fieldsList.toList))
}
def readMoviesFile(filepath: String) : Map[Int, Movie] ={
val reader = MyCsvReader.reader(filepath)
val csv_list = reader.allWithHeaders()
reader.close()
csv_list.map { entry =>
val parseResult: (Int, Movie) = parseMovieEntry(entry)
parseResult._1 -> parseResult._2
}(collection.breakOut): Map[Int, Movie]
}
def parseTrainEntry(csv_entry: List[String], moviesMap: Map[Int, Movie]): (Int, Evaluation) ={
val personId = csv_entry(1)
val movieId = csv_entry(2)
val grade = csv_entry(3)
(personId.toInt, new Evaluation(grade = grade.toInt, movie = moviesMap(movieId.toInt)))
}
def readTrainSetFile(filepath: String, moviesMap: Map[Int, Movie]): Map[Int, List[Evaluation]] ={
val reader = MyCsvReader.reader(filepath)
val csv_list: List[List[String]] = reader.all()
reader.close()
val parsedTuples = csv_list.map { entry =>
val parseResult: (Int, Evaluation) = parseTrainEntry(entry, moviesMap)
parseResult._1 -> parseResult._2
}
parsedTuples.groupBy(_._1).mapValues(_.map(_._2))
}
def parseUnknownEntry(csv_entry: List[String]): (Int, Int, Int) ={
val evalId = csv_entry(0)
val personId = csv_entry(1)
val movieId = csv_entry(2)
(evalId.toInt, personId.toInt, movieId.toInt)
}
def readUnknowns(filepath: String): List[(Int, Int, Int)] ={
val reader = MyCsvReader.reader(filepath)
val csv_list: List[List[String]] = reader.all()
reader.close()
csv_list.map { entry =>
parseUnknownEntry(entry)
}
}
}
开发者ID:CucumisSativus,项目名称:decision-tree-movie-evaluator,代码行数:59,代码来源:InputParsers.scala
示例5: ReportServiceActor
//设置package包名称以及导入依赖的类
package com.github.unknownnpc.remotedebugtool.actor
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import com.github.unknownnpc.remotedebugtool.config.{AppConfig, RemoteDebugToolConfig}
import com.github.unknownnpc.remotedebugtool.domain._
import com.github.unknownnpc.remotedebugtool.exception.ReportException
import com.github.unknownnpc.remotedebugtool.message.{MainAppActorStop, ReportServicePayload, ReportServicePrint}
import scala.collection.mutable.ListBuffer
class ReportServiceActor(mainAppActorRef: ActorRef) extends Actor with ActorLogging {
self: AppConfig =>
val values = ListBuffer.empty[ReportRow]
override def receive = {
case ReportServicePayload(payload) =>
log.debug(s"Print service received incoming payload: [$payload]")
values += reportRowFrom(payload)
case ReportServicePrint =>
log.debug(s"Received print command")
log.info(systemConfig.reportFormatter.format(values.toList))
mainAppActorRef ! MainAppActorStop
}
private def reportRowFrom(payload: BreakpointPayload) = {
val testTarget = findServerById(payload.breakpoint.targetId)
JvmReportRow(testTarget.id,
testTarget.address,
testTarget.port,
payload.breakpoint.line,
payload.breakpoint.className,
payload.breakpointValue
)
}
private def findServerById(id: ID) = {
servers.find(_.id == id).getOrElse(
throw ReportException("Unable to match payload to server instance")
)
}
}
object ReportServiceActor {
def props(mainAppActorRef: ActorRef) =
Props(new ReportServiceActor(mainAppActorRef) with RemoteDebugToolConfig)
}
开发者ID:UnknownNPC,项目名称:remote-debug-tool,代码行数:54,代码来源:ReportServiceActor.scala
示例6: ChunkedHermesGameFileEntries
//设置package包名称以及导入依赖的类
package proton.game.hermes
import java.util.UUID
import akka.actor.ActorLogging
import akka.event.LoggingReceive
import akka.persistence.PersistentActor
import scala.collection.mutable.ListBuffer
object ChunkedHermesGameFileEntries {
trait EntriesMessage
case class AppendEntries(entries: Seq[HermesGameFileEntry]) extends EntriesMessage
case class GetEntries() extends EntriesMessage
trait EntriesEvent
case class EntriesAppended(entries: Seq[HermesGameFileEntry]) extends EntriesEvent
trait EntriesResult
case class EntriesAppendedResult(id: UUID, count: Int) extends EntriesResult
case class GetEntriesResult(id: UUID, entries: Seq[HermesGameFileEntry]) extends EntriesResult
val gameFileEntriesRegionName = "hermesGameFileEntries"
}
class ChunkedHermesGameFileEntries(moduleSettings: HermesGameTickerModuleSettings) extends PersistentActor with ActorLogging {
import context._
import ChunkedHermesGameFileEntries._
private val _id: UUID = UUID.fromString(self.path.name)
private val _entries = new ListBuffer[HermesGameFileEntry]()
setReceiveTimeout(moduleSettings.chunkedTimeout)
override def receiveRecover: Receive = {
case event: EntriesEvent => updateState(event)
}
def updateState(e: EntriesEvent) = e match {
case EntriesAppended(entries) => _entries ++= entries
}
override def receiveCommand: Receive = LoggingReceive {
case AppendEntries(entries) =>
if (entries.nonEmpty) {
persist(EntriesAppended(entries))(e => {
updateState(e)
sender ! EntriesAppendedResult(_id, entries.size)
})
} else {
sender ! EntriesAppendedResult(_id, 0)
}
case GetEntries() => sender ! GetEntriesResult(_id, _entries)
}
override def persistenceId: String = "hermes-game-file-entries-" + _id.toString
}
开发者ID:Morgan-Stanley,项目名称:proton,代码行数:58,代码来源:ChunkedHermesGameFileEntries.scala
示例7: StatisticsWindow
//设置package包名称以及导入依赖的类
package org.hpi.esb.datavalidator.validation
import org.hpi.esb.datavalidator.data.{SimpleRecord, Statistics}
import scala.collection.mutable.ListBuffer
class StatisticsWindow(firstTimestamp: Long, windowSize: Long) extends Window(firstTimestamp, windowSize) {
var stats = new Statistics()()
override def update(): Unit = {
super.update()
stats = new Statistics()()
}
def addValue(value: Long, timestamp: Long): Unit = {
stats = stats.getUpdatedWithValue(timestamp, value)
}
def takeRecords(records: ListBuffer[SimpleRecord]): ListBuffer[SimpleRecord] = {
val (windowValues, rest) = records.span(r => containsTimestamp(r.timestamp))
windowValues.foreach(r => addValue(r.value, r.timestamp))
rest
}
}
开发者ID:BenReissaus,项目名称:EnterpriseStreamingBenchmark,代码行数:26,代码来源:StatisticsWindow.scala
示例8: BagSpecs
//设置package包名称以及导入依赖的类
package de.htwg.se.SevenSteps.model.bag.basicImpl
import org.junit.runner.RunWith
import org.scalatest.Matchers._
import org.scalatest._
import org.scalatest.junit.JUnitRunner
import scala.collection.mutable.ListBuffer
@RunWith(classOf[JUnitRunner])
class BagSpecs extends WordSpec {
def getBag: Bag = Bag(Vector(), Vector("a", "b"))
"A Bag" should {
"have a insert function" in {
val bag = getBag
bag.insert('a')
bag.insert('b')
bag.insert('c')
bag.bag should be(ListBuffer("a", "b", "c"))
}
"have a reset function" in {
val bag = getBag
bag.insert('a')
bag.reset.bag should be(ListBuffer())
}
"have a draw function" in {
val bag = getBag
bag.insert('a')
bag.get() should be(Some('a'))
bag.get() should be(None)
}
"can fillUp with the colors" in {
val bag = getBag
bag.fillup()
}
"can get the stone number" in {
val bag = getBag
bag.getStoneNumber should be(0)
bag.insert('a')
bag.getStoneNumber should be(1)
}
"have a toXML functions" in {
val bag = getBag
bag.insert('a')
bag.insert('b')
bag.insert('c')
bag.toXML().toString() should be("<alles a='<blub bag2=\"a\"></blub><blub bag2=\"b\"></blub><blub" +
" bag2=\"c\"></blub>' b='<bag col=\"a\"></bag><bag col=\"b\"></bag>'></alles>")
}
}
}
开发者ID:GrimmT,项目名称:de.htwg.se.SevenSteps,代码行数:51,代码来源:BagSpecs.scala
示例9: Field
//设置package包名称以及导入依赖的类
package de.htwg.se.scotlandyard.model.impl
import com.google.inject.Singleton
import de.htwg.se.scotlandyard.model.TField
import scala.collection.mutable.ListBuffer
@Singleton
case class Field() extends TField {
override var fieldM = scala.collection.mutable.Map.empty[Int, Node]
var stream = Field.getClass.getResourceAsStream("/Knoten.txt")
for (line <- scala.io.Source.fromInputStream( stream ).getLines) {
var data = line.split(" ")
val pcon : ListBuffer[(Int, String)] = ListBuffer()
fieldM += (data(0).toInt -> Node(data(0).toInt,false,data(1).toInt,data(2).toInt, pcon))
}
stream = Field.getClass.getResourceAsStream("/Kanten.txt")
for (line <- scala.io.Source.fromInputStream( stream ).getLines) {
var data = line.split(" ")
fieldM(data(0).toInt).pcon.+=:(data(1).toInt,data(2))
}
stream = Field.getClass.getResourceAsStream("/Kanten.txt")
for (line <- scala.io.Source.fromInputStream( stream ).getLines) {
var data = line.split(" ")
fieldM(data(1).toInt).pcon.+=:(data(0).toInt,data(2))
}
override def reset = new Field()
override def prettyPconList(fieldNo: Int): String = {
var sb = new StringBuilder
var i = 0
val rfield = fieldM(fieldNo).pcon.toList
sb.append("Possible Moves: \n")
for (a <- 0 until rfield.length) {
sb.append("(" + a + ")" + rfield(a) + "\n")
}
sb.toString()
}
override def toString = {
var a = 199
var sb = new StringBuilder()
for (a <- 1 to 199) {
if (fieldM(a).occ == true) {
sb.append(fieldM(a).no.toString + " " + fieldM(a).occ.toString + "\n")
}
}
sb.toString()
}
}
开发者ID:maximiliangraebel,项目名称:ScotlandYard,代码行数:56,代码来源:Field.scala
示例10: restart
//设置package包名称以及导入依赖的类
package de.htwg.se.scotlandyard.controller
import java.util
import de.htwg.se.scotlandyard.model.impl.Player
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.swing.Publisher
trait TScotlandYardController extends Publisher {
var field : de.htwg.se.scotlandyard.model.TField
var players: Array[Player]
var caught : Boolean
var statusText : String
var startPosList : ListBuffer[Int]
var playerlist : Array[Player]
var moveList : util.ArrayList[String]
var moveListPublic : util.ArrayList[String]
var moveStackAll : mutable.Stack[(Int, Int, String, Int)]
var roundCounter : Int
var currentPlayer : Int
var previousPlayer : Int
var chosenCard : String
def restart(): Unit
def move(connectionPos: Int): Unit
def moveGUI(newPosition: Int, usedCard: String, optionsNeeded: Boolean): Unit
def checkOcc(pos: Int): Boolean
def enoughCards(typ: String, player: Int): Boolean
def useCard(typ: String, player: Int): Unit
def startPos(player:Int): Unit
def misterxMoves(): util.ArrayList[String]
def addMisterxMoves(newPos: Int, usedCard: String): Unit
def playerPositions(): String
def playerInfo(player: Int) : String
def undoMove(): Unit
def toXml() : scala.xml.Node
def fromXml (node: scala.xml.Node): String
def saveGame() : Unit
}
开发者ID:maximiliangraebel,项目名称:ScotlandYard,代码行数:44,代码来源:TScotlandYardController.scala
示例11: TranscriberDemo
//设置package包名称以及导入依赖的类
package org.rwalk.legalchatter
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
import edu.cmu.sphinx.api.Configuration
import edu.cmu.sphinx.api.SpeechResult
import edu.cmu.sphinx.api.StreamSpeechRecognizer
import edu.cmu.sphinx.decoder.adaptation.Transform
import org.rwalk.legalchatter.LegalChatterUtils
import collection.JavaConversions._
import scala.collection.mutable.ListBuffer
object TranscriberDemo {
def main(args:Array[String]) {
println("Performing recognition.")
val recognizer = new StreamSpeechRecognizer(Configurator.sphinxConfig)
recognizer.startRecognition(LegalChatterUtils.decodeMP3Stream(args(0)))
var result = recognizer.getResult
val words = new ListBuffer[String]
while (result != null) {
println(s"Hypothesis: ${result.getHypothesis()}\n")
println("List of recognized words and their times:")
result.getWords() foreach println
println("Best 3 hypothesis:")
result.getNbest(3) foreach println
words.append(result.getHypothesis)
result = recognizer.getResult
}
recognizer.stopRecognition()
println(s"TRANSCRIPTION: \n ${words.mkString(" ")}")
}
}
开发者ID:rwalk,项目名称:legal-chatter,代码行数:42,代码来源:TranscriberDemo.scala
示例12: ProcessBuilderUtils
//设置package包名称以及导入依赖的类
package util
import java.io.ByteArrayInputStream
import java.nio.charset.{Charset, CodingErrorAction}
import text.StringOption
import scala.collection.mutable.ListBuffer
import scala.io.{Codec, Source}
import scala.sys.process.ProcessBuilder
object ProcessBuilderUtils {
implicit def processToProcessUtils(repr: ProcessBuilder): ProcessBuilderUtils = {
new ProcessBuilderUtils(repr)
}
}
class ProcessBuilderUtils(repr: ProcessBuilder) {
def lineStream(encoding: Charset,
onMalformedInput: CodingErrorAction,
onUnmappableCharacter: CodingErrorAction,
replacementOpt: StringOption): Iterator[String] = {
val lines: Iterator[String] = repr.lineStream_!.iterator
val byteBuffer = ListBuffer.empty[Byte]
while (lines.hasNext) {
val line: String = lines.next.trim concat "\n"
byteBuffer ++= line.getBytes
}
implicit val codec = Codec(encoding).
onMalformedInput(onMalformedInput).
onUnmappableCharacter(onUnmappableCharacter)
if (replacementOpt.nonEmpty) {
codec.decodingReplaceWith(replacementOpt.get)
}
Source.fromInputStream(new ByteArrayInputStream(byteBuffer.toArray)).getLines
}
}
开发者ID:ynupc,项目名称:scalastringcourseday7,代码行数:39,代码来源:ProcessBuilderUtils.scala
示例13: GpxFileReader
//设置package包名称以及导入依赖的类
package eu.kraml.io
import java.io.File
import java.nio.file.Path
import java.time.Instant
import java.time.format.DateTimeFormatter
import eu.kraml.model.{GpsCoordinate, Record}
import scala.collection.mutable.ListBuffer
import scala.xml.XML
object GpxFileReader {
val formatter = DateTimeFormatter.ISO_INSTANT
def read(gpxFile: Path): Option[List[Record]] = {
read(gpxFile.toFile)
}
def read(gpxFile: File): Option[List[Record]] = {
try {
Some(readInternal(gpxFile))
} catch {
case e:Exception =>
None
}
}
private def readInternal(gpxFile: File): List[Record] = {
val gpx = XML.loadFile(gpxFile)
val segment = gpx \ "trk" \ "trkseg"
val points = segment \ "trkpt"
val records = ListBuffer[Record]()
points.foreach(n => {
val lat = n.attribute("lat").get.head.text
val lon = n.attribute("lon").get.head.text
val timestampText = (n \ "time").text
val timestamp = Instant.parse(timestampText)
records += Record(new GpsCoordinate(lat.toDouble, lon.toDouble), timestamp)
})
records.toList
}
}
开发者ID:jkraml,项目名称:gpsplot,代码行数:45,代码来源:GpxFileReader.scala
示例14: NamedEntityController
//设置package包名称以及导入依赖的类
package controllers
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
import scala.util.{Failure, Success, Try}
import javax.inject._
import play.api.libs.json.{JsArray, JsValue, Json}
import play.api.mvc._
import IndonesianNLP._
@Singleton
class NamedEntityController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
val nETagger = new IndonesianNETagger
def tagger: Action[JsValue] = Action(parse.json) { implicit request: Request[JsValue] =>
val string = (request.body \ "string").as[String]
Try {
nETagger.extractNamedEntity(string)
} match {
case Success(extracted) =>
val namedEntityList = new ListBuffer[JsValue]()
for(tag <- extracted.asScala) {
namedEntityList += Json.toJson(tag)
}
Ok(Json.obj("status" -> "success", "data" -> JsArray(namedEntityList)))
case Failure(failure) => InternalServerError(Json.obj("status" -> "error", "message" -> failure.toString))
}
}
}
开发者ID:panggi,项目名称:pujangga,代码行数:34,代码来源:NamedEntityController.scala
示例15: PhraseController
//设置package包名称以及导入依赖的类
package controllers
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
import scala.util.{Failure, Success, Try}
import javax.inject._
import play.api.libs.json.{JsArray, JsValue, Json}
import play.api.mvc._
import IndonesianNLP._
@Singleton
class PhraseController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
val phraseChunker = new IndonesianPhraseChunker
def chunker: Action[JsValue] = Action(parse.json) { implicit request: Request[JsValue] =>
val string = (request.body \ "string").as[String]
Try {
phraseChunker.doPhraseChunker(string)
} match {
case Success(chunked) =>
val chunkListString = new ListBuffer[String]()
val chunkListJs = new ListBuffer[JsValue]()
for(chunk <- chunked.asScala) {
for(phrase <- chunk) {
chunkListString += phrase
if(chunk.indexOf(phrase) % 2 == 1) {
chunkListJs += Json.toJson(phrase)
}
}
}
val chunkMap = chunkListString.grouped(2).collect { case ListBuffer(k, v) => k -> v }.toMap
Ok(Json.obj("status" -> "success", "data" -> Json.obj("map" -> Json.toJson(chunkMap), "list" -> JsArray(chunkListJs))))
case Failure(failure) => InternalServerError(Json.obj("status" -> "error", "message" -> failure.toString))
}
}
}
开发者ID:panggi,项目名称:pujangga,代码行数:41,代码来源:PhraseController.scala
示例16: Login
//设置package包名称以及导入依赖的类
package chehao.chat
import scala.collection.mutable.ListBuffer
sealed trait Event {
}
case class Login(user: String) extends Event
case class Logout(user: String) extends Event
case class GetChatLog(from: String) extends Event
case class ChatLog(log: ListBuffer[String]) extends Event
case class ChatMessage(from: String, message: String) extends Event
case class ChatMessageTo(from: String, to: String, message: String) extends Event
case class GetChatMessageTo(from:String,to:String) extends Event
case class AddFriend(user: String, friend: String) extends Event
case class ChangeTo(to: String) extends Event
开发者ID:Chehao,项目名称:Akkala,代码行数:17,代码来源:Event.scala
示例17: ApplicantDataSpec
//设置package包名称以及导入依赖的类
package applicant.etl
import org.scalatest.FlatSpec
import org.scalatest.MustMatchers._
import scala.collection.mutable.{LinkedHashMap, ListBuffer, HashMap}
class ApplicantDataSpec extends FlatSpec {
val input: LinkedHashMap[(String, String),(String, String)] = LinkedHashMap[(String, String),(String, String)]()
input += (("person" -> "jason frederick") -> ("person" -> "Jason Frederick"))
input += (("title" -> "web develoer") -> ("title" -> "Web Developer"))
input += (("organization" -> "american financial group, inc.") -> ("organization" -> "American Financial Group, Inc."))
input += (("location" -> "thousand oaks, ca") -> ("location" -> "Thousand Oaks, CA"))
input += (("title" -> "etl developer") ->("title" -> "ETL Developer"))
input += (("organization" -> "alaska air group, inc.") -> ("organization" -> "Alaska Air Group, Inc."))
input += (("location" -> "columbus, ga") -> ("location" -> "Columbus, GA"))
input += (("webapp" -> "javascript") -> ("webapp" -> "JavaScript"))
input += (("degree" -> "bs biology") -> ("degree" -> "BS Biology"))
input += (("school" -> "harvard university") -> ("school" -> "Harvard University"))
val applicant: ApplicantData = ApplicantData(input, "Wow what a good resume name", "This is totally the text that gave us these entities :D")
val map = applicant.toMap()
"ApplicantData" must "store the name" in {
map.get("name").get mustBe ("Jason Frederick")
}
"ApplicantData" must "store the first title" in {
map.get("currentLocation").get.asInstanceOf[HashMap[String, String]].get("title") mustBe (Some("Web Developer"))
}
"ApplicantData" must "store the first location" in {
map.get("currentLocation").get.asInstanceOf[HashMap[String, String]].get("location") mustBe (Some("Thousand Oaks, CA"))
}
"ApplicantData" must "store the first organization" in {
map.get("currentLocation").get.asInstanceOf[HashMap[String, String]].get("organization") mustBe (Some("American Financial Group, Inc."))
}
"ApplicantData" must "store the first degree" in {
map.get("education").get.asInstanceOf[HashMap[String, String]].get("degree") mustBe (Some("BS Biology"))
}
"ApplicantData" must "store the first school" in {
map.get("education").get.asInstanceOf[HashMap[String, String]].get("school") mustBe (Some("Harvard University"))
}
"ApplicantData" must "add JavaScript to the webapp list" in {
map.get("skills").get.asInstanceOf[HashMap[String, ListBuffer[String]]].get("webapp").get.contains("JavaScript") mustBe (true)
}
"ApplicantData" must "store the resume text" in {
map.get("additionalInfo").get.asInstanceOf[HashMap[String, String]].get("resume") mustBe (Some("This is totally the text that gave us these entities :D"))
}
}
开发者ID:dataworks,项目名称:internship-2016,代码行数:57,代码来源:ApplicantDataSpec.scala
示例18: ExperienceFeature
//设置package包名称以及导入依赖的类
package applicant.ml.regression.features
import applicant.etl.ApplicantData
import applicant.ml.regression.FeatureSetting
import scala.collection.mutable.{ListBuffer, Map}
import scala.collection.JavaConversions.JListWrapper
class ExperienceFeature(newSetting: FeatureSetting) extends BaseFeature {
val setting = newSetting
def getFeatureScore(applicant: ApplicantData): Double = {
val infoMap = setting.values(0).asInstanceOf[Map[String,JListWrapper[AnyRef]]]
val positionKeywords: ListBuffer[String] = infoMap("positions").asInstanceOf[JListWrapper[String]].toList.to[ListBuffer]
val degreeKeywords: ListBuffer[String] = infoMap("degrees").asInstanceOf[JListWrapper[String]].toList.to[ListBuffer]
var rawGPA = applicant.gpa
//Scale the gpa by the type of degree
if (checkDegree(applicant.degree, degreeKeywords)) {
rawGPA = gpaScaler(rawGPA, 0.5)
} else {
rawGPA *= gpaScaler(rawGPA, 0.25)
}
var positionScore = 0.0
positionScore = checkPosition(positionScore, applicant.recentTitle, positionKeywords)
for (position <- applicant.otherTitleList) {
positionScore = checkPosition(positionScore, applicant.recentTitle, positionKeywords)
}
val maxScore = Math.max(rawGPA, positionScore) / 4.0
return if (maxScore > 1.0) 1.0 else maxScore
}
}
开发者ID:dataworks,项目名称:internship-2016,代码行数:37,代码来源:ExperienceFeature.scala
示例19: RelevanceFeature
//设置package包名称以及导入依赖的类
package applicant.ml.regression.features
import applicant.etl.ApplicantData
import applicant.nlp.LuceneTokenizer
import applicant.ml.regression.FeatureSetting
import applicant.ml.naivebayes.{NaiveBayesFeatureGenerator, NaiveBayesHelper}
import scala.collection.mutable.ListBuffer
import org.apache.spark.mllib.classification.NaiveBayesModel
import org.apache.spark.mllib.feature.IDFModel
class RelevanceFeature(newSetting: FeatureSetting, naiveBayesModel: NaiveBayesModel, tfIdfModel: IDFModel) extends BaseFeature {
val setting: FeatureSetting = newSetting
val bayesModel: NaiveBayesModel = naiveBayesModel
val idfModel: IDFModel = tfIdfModel
def getFeatureScore(applicant: ApplicantData): Double = {
val tokenList = LuceneTokenizer.getTokens(applicant.fullText)
var scores = new ListBuffer[Double]()
tokenList.foreach { tokens =>
val score = NaiveBayesHelper.predictSingleScore(bayesModel, NaiveBayesFeatureGenerator.getAdjustedFeatureVec(tokens, idfModel))
scores += score
}
// Filter overconfident scores. Model confidence with vary more with larger training sets.
scores = scores.filter { score =>
score < 0.95 && score > 0.05
}
var result = 0.0
if (scores.length > 0) {
result = scores.sum / scores.length
}
return result
}
}
开发者ID:dataworks,项目名称:internship-2016,代码行数:40,代码来源:RelevanceFeature.scala
示例20: KeywordFeature
//设置package包名称以及导入依赖的类
package applicant.ml.regression.features
import applicant.etl.ApplicantData
import applicant.nlp.LuceneTokenizer
import applicant.ml.regression.FeatureSetting
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.HashMap
class KeywordFeature(newSetting: FeatureSetting) extends BaseFeature {
val setting = newSetting
def getFeatureScore(applicant: ApplicantData): Double = {
val keywordList: ListBuffer[String] = newSetting.values.asInstanceOf[ListBuffer[String]]
val tokenizer = new LuceneTokenizer()
val resumeArray = tokenizer.tokenize(applicant.fullText) //Converts to lowercase
var matches : Double = 0.0
val map = HashMap.empty[String, Int]
for (item <- keywordList) {
map += (item.toLowerCase -> 0)
}
resumeArray.foreach { word =>
if (map.contains(word)){
val currentWordCount = map(word)
map += (word -> (currentWordCount + 1))
}
}
map.foreach{ case (k,v) =>
if (v >= 2){
if (v > 5) {
matches += 5.0
}
else {
matches += v.toDouble
}
}
}
val rawScore = matches/(map.size*4.0)
return if (rawScore > 1.0) 1.0 else rawScore
}
}
开发者ID:dataworks,项目名称:internship-2016,代码行数:49,代码来源:KeywordFeature.scala
注:本文中的scala.collection.mutable.ListBuffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论