当前位置: 首页 剧情 金钱豹子汤隆
手机观看

金钱豹子汤隆 (2014)

2014/大陆/ 剧情 犯罪 武侠 古装

HD高清

排序

播放地址

剧情简介

" // 词典中放了很多优化规则 let defaultToken = " " let maxToken = 100 let minToken = 0 var tokenRange = minToken...maxToken var pinyinFirst: String = "" var pinyinLast: String = "" // 拼接全部拼音 var pinyinAll = "" var leftLength = "" var rightLength = "" var pinyinLength = "" var title = "" var other = "" var prev = "" var cur = "" var next = "" var headNumber = 0 var tailNumber = 0 var itemList = ["title":title,"other":other,"prev":prev,"cur":cur,"next":next,"pinyinFirst":pinyinFirst,"pinyinLast":pinyinLast,"leftLength":leftLength,"rightLength":rightLength,"pinyinLength":pinyinLength] /// 切词 /// /// - Parameters: /// - text: 初始文本 /// - token: 切词符 func getWordsList(text: String, prevent: String) -> [String] { var wordsList:[String] = [] do { let regex = try NSRegularExpression(pattern: "[^(prevent)\s] ", options: []) regex.enumerateMatches(in:text, options:[], range:NSMakeRange(0, text.characters.count)) { (result, flags, pointer) in let range = result?.range let subtext = (text as NSString).substring(with:range!)// print(subtext) wordsList.append(subtext) } } catch { print("getWordsList error") } return wordsList } /// 优化文本 /// title 40 pinyinLength 50 prev 5 cur 5 next 5 /// /// - Parameters: /// - text: 初始文本 /// - token: 切词符 /// - Returns: 优化后文本 mutating func optimizedText(text: String, prevent: String) -> String { var list = getWordsList(text: text, prevent: prevent) var str = "" headNumber = 0 tailNumber = 0 var tempindex = 0 for item in list { if item == "" { continue } str.append(item) // 拼接 if item.characters.count > 1 || (item.characters.count == 1 && isChinese(item)) { pinyinAll = prev cur item next } else { pinyinAll = "" } // 优化 var optimize = optimizeAll(pinyinString: pinyinAll) pinyinFirst = optimize.pinyinFirst pinyinLast = optimize.pinyinLast leftLength = optimize.leftLength rightLength = optimize.rightLength pinyinLength = optimize.pinyinLength // 计算headNumber tailNumber headNumber = leftLength.characters.count pinyinFirst.characters.count tailNumber = (rightLength pinyinLast).characters.count tempindex = 1 if tempindex == list.count { continue } if tempindex < list.count - 1 { prev = cur cur = next next = list[tempindex 1] } } // 整理后的数据 itemList["title"] = str itemList["other"] = "(tailNumber pinyinLength.characters.count)" itemList["prev"] = "(headNumber)" itemList["cur"] = "(pinyinFirst.characters.count)" itemList["next"] = "(pinyinLength.characters.count)" itemList["pinyinFirst"] = pinyinFirst itemList["pinyinLast"] = pinyinLast itemList["leftLength"] = leftLength itemList["rightLength"] = rightLength itemList["pinyinLength"] = pinyinLength return str } /// 优化方法 /// 1、汉字开头将中文转为拼音首字母 /// 2、全部拼音首字母小写 /// 3、拼音间用空格下划线隔开 /// /// - Parameter pinyinString: 未优化的拼音字符串 /// - Returns: 优化后的拼音 private func optimizeAll(pinyinString: String) -> (pinyinFirst: String, pinyinLast: String, leftLength: String, rightLength: String, pinyinLength: String) { var pinyinFirst = "" var pinyinLast = "" var pinyinLength = "" var leftLength = "" var rightLength = "" let words = pinyinString.characters.split(separator: " ", maxSplits: Int.max, omittingEmptySubsequences: false) for (index, item) in words.enumerated() { let temp = item.reversed() if temp.count <= 1 { var tempString = "" for i in item.reversed() { tempString = String(i) } pinyinFirst = tempString continue } for (i, a) in temp.enumerated() { if i == temp.count - 1 { pinyinLast = "(a)" } else { pinyinFirst = "(a)" } } } leftLength = "(pinyinFirst.characters.count)" rightLength = "(pinyinLast.characters.count)" pinyinLength = pinyinFirst pinyinLast return (pinyinFirst, pinyinLast, leftLength, rightLength, pinyinLength) } /// 中文词数量 /// /// - Parameter text: 文本 /// - Returns: 中

本站所有视频和图片均来自互联网收集而来,本网站只提供web页面服务,并不提供资源存储,也不参与录制、上传
若本站收录的节目无意侵犯了贵司版权,请发邮件至123456@test.cn (我们会在3个工作日内删除侵权内容,谢谢。)

Copyright © 2019 火豆电影网 icp123