I want to split a string delimited by commas and use the result as either a Seq or a Set:
def splitByComma(commaDelimited: String): Array[String]
= commaDelimited.trim.split(',')
def splitByCommaAsSet(commaDelimited: String): Set[String]
= splitByComma(commaDelimited).toSet
def splitByCommaAsSeq(commaDelimited: String): Seq[String]
= splitByComma(commaDelimited).toSeq
val foods = "sushi,taco,burrito"
val foodSet = splitByCommaAsSet(foods)
// foodSet: scala.collection.immutable.Set[String] = Set(sushi, taco, burrito)
val foodSeq = splitByCommaAsSeq(foods)
// foodSeq: Seq[String] = List(sushi, taco, burrito)
Run Code Online (Sandbox Code Playgroud)
However, this is quite repetitive. Ideally, I would want to have something like genericSplitByComma[Set](foods) that …
generics polymorphism scala type-conversion scala-collections
当标记包含中文和英文的文本时,结果会将英文单词分成字母,这不是我想要的.请考虑以下代码:
from nltk.tokenize.stanford_segmenter import StanfordSegmenter
segmenter = StanfordSegmenter()
segmenter.default_config('zh')
print(segmenter.segment('?????Melissa Dell'))
Run Code Online (Sandbox Code Playgroud)
输出将是???? ? M e l i s s a D e l l.如何修改此行为?