本文整理汇总了Scala中scala.collection.immutable.SortedMap类的典型用法代码示例。如果您正苦于以下问题:Scala SortedMap类的具体用法?Scala SortedMap怎么用?Scala SortedMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SortedMap类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: FeatureSet
//设置package包名称以及导入依赖的类
package edu.knowitall.tool.conf
import scala.collection.immutable.SortedMap
class FeatureSet[T, V](val featureMap: SortedMap[String, Feature[T, V]]) {
def this() = this(SortedMap.empty[String, Feature[T, V]])
def apply(name: String) = featureMap(name)
def featureNames(): Seq[String] =
featureMap.keys.toSeq
def numFeatures(): Int =
featureNames.size
def vectorize(example: T): Seq[V] =
featureNames.map({ name =>
val featureFunction = featureMap(name)
featureFunction(example)
})(scala.collection.breakOut)
}
object FeatureSet {
val binaryClass = true
def apply[T, V](features: Iterable[Feature[T, V]]): FeatureSet[T, V] = {
new FeatureSet[T, V](SortedMap.empty[String, Feature[T, V]] ++
features.map(feature => (feature.name, feature)))
}
}
示例2: RhetoricalTypes
//设置package包名称以及导入依赖的类
package au.edu.utscic.athanorserver.data
import scala.collection.immutable.SortedMap
object RhetoricalTypes {
type LexicalNodes = SortedMap[Int,Node]
type ConstituentTree = List[Any]
type Dependencies = List[Dependency]
type ParsedSentence = (LexicalNodes,ConstituentTree,Dependencies)
case class Node(
id:Int,
POS:String,
surface:Option[String],
lemma:Option[String],
NER:Option[String] = None,
Speaker:Option[String] = None,
left:Option[Int] = None,
right:Option[Int] = None
)
case class Dependency(
name:String,
governor:Int,
dependent:Int
)
}
示例3: PStringTest
//设置package包名称以及导入依赖的类
package com.avsystem.scex
package compiler.xmlfriendly
import com.avsystem.scex.parsing.{Modification, PString, ShiftInfo}
import org.scalatest.FunSuite
import scala.collection.immutable.SortedMap
class PStringTest extends FunSuite {
def test(name: String)(modifications: Modification*)
(shiftMapping: (Int, ShiftInfo)*)(reverseShiftMapping: (Int, ShiftInfo)*): Unit = super.test(name) {
val (actualShiftMapping, actualReverseShiftMapping) =
PString.computeMapping(modifications.toList, Nil, Nil)
assert(actualShiftMapping === SortedMap(shiftMapping: _*), "actual mapping")
assert(actualReverseShiftMapping === SortedMap(reverseShiftMapping: _*), "reverse mapping")
}
test("no modifications test")()()()
test("single add test")(
Modification(0, 5))(
0 -> ShiftInfo(0, 5, 0))(
0 -> ShiftInfo(0, 0, 5))
test("single remove test")(
Modification(0, -5))(
0 -> ShiftInfo(0, 0, 5))(
0 -> ShiftInfo(0, 5, 0))
test("remove+add replace test")(
Modification(0, -5), Modification(0, 3))(
0 -> ShiftInfo(0, 3, 5))(
0 -> ShiftInfo(0, 5, 3))
test("add+remove replace test")(
Modification(0, 3), Modification(0, -5))(
0 -> ShiftInfo(0, 3, 5))(
0 -> ShiftInfo(0, 5, 3))
test("consecutive remove and add test")(
Modification(0, -5), Modification(5, 3))(
0 -> ShiftInfo(0, 0, 5), 5 -> ShiftInfo(-5, 3, 0))(
0 -> ShiftInfo(0, 5, 3))
test("complex test")(
Modification(2, 5), Modification(3, -4), Modification(10, -2), Modification(12, 4))(
2 -> ShiftInfo(0, 5, 0), 3 -> ShiftInfo(5, 0, 4), 10 -> ShiftInfo(1, 0, 2), 12 -> ShiftInfo(-1, 4, 0))(
2 -> ShiftInfo(0, 0, 5), 8 -> ShiftInfo(-5, 4, 0), 11 -> ShiftInfo(-1, 2, 4))
}
示例4: MapTuple
//设置package包名称以及导入依赖的类
import scala.collection.immutable.SortedMap
object MapTuple {
def main(args: Array[String]) {
val map = Map("book" -> 10,"gun" -> 18,"ipad" -> 1000)
for((k,v) <- map) yield (k,v*0.9)
val scores = scala.collection.mutable.Map("scala" -> 7,"Hadoop" -> 8, "Spark" ->10 )
val hadoopScore = scores.getOrElse("Hadoop",0)
scores += ("R" -> 0)
scores -= "Hadoop"
val sortedScore = SortedMap("SCALA" -> 7, "Hadoop" -> 8, "spark" -> 10)
val tuple = (1,2,3.14,"Rocky","Spark")
val third = tuple._3
//??tuple?????first,second...
val (first,second,thirda,fourth,fifth) = tuple
//???
val (f1,s1,_,_,_) = tuple
//??????????
"Rocky Spark".partition(_.isUpper)
val symbols = Array("[","-","]")
val counts = Array(2,5,2)
//????,???????Array
val pairs = symbols.zip(counts)
//?? [[-----]]
for ((x,y) <- pairs) print(x*y)
}
}