我实际上是groovy的新手,我正在尝试读取json文档文件,并统计在json文档字段中出现的特定单词“温度”的次数。单词应该完全匹配。比如"high_temperature不应该等于"temperature“,只有"temperature”应该等于"temperature“。
def file = new File('src/main/resources/climate_change_tweets_all.json')
file.each{
if (it.contains(" temperature ")){
temperature++
}
}发布于 2019-11-10 06:16:00
忽略该格式,您可以简单地
def file = new File('src/main/resources/climate_change_tweets_all.json')
int count = file.text.count ' temperature '如果需要区分大小写或单词位置,则必须使用regexp:
int count = 0
file.text.eachMatch( /\btemperature\b/ ){ count++ }https://stackoverflow.com/questions/58769716
复制相似问题