附注




   let url = Bundle.main.url(forResource: "baidu_stopwords", withExtension: "csv")!
//            let result = try! DataFrame(contentsOfCSVFile: url,options: CSVReadingOptions(
//                hasHeaderRow: true))
//         let  停用词1 = Array(result["停用词", String.self])

 

struct AsyncButton<Label: View>: View {
    var action: () async -> Void
    @ViewBuilder var label: () -> Label

    @State private var isPerformingTask = false

    var body: some View {
        Button(
            action: {
                isPerformingTask = true
            
                Task {
                    await action()
                    isPerformingTask = false
                }
            },
            label: {
                ZStack {
                    // We hide the label by setting its opacity
                    // to zero, since we don't want the button's
                    // size to change while its task is performed:
                    label().opacity(isPerformingTask ? 0 : 1)

                    if isPerformingTask {
                        ProgressView()
                    }
                }
            }
        )
        .disabled(isPerformingTask)
    }
}

extension Array: RawRepresentable where Element: Codable {
    public init?(rawValue: String) {
        guard let data = rawValue.data(using: .utf8),
              let result = try? JSONDecoder().decode([Element].self, from: data)
        else { return nil }
        self = result
    }

    public var rawValue: String {
        guard let data = try? JSONEncoder().encode(self),
              let result = String(data: data, encoding: .utf8)
        else {
            return "[]"
        }
        return result
    }
}

extension Date:RawRepresentable{
    public typealias RawValue = String
    public init?(rawValue: RawValue) {
        guard let data = rawValue.data(using: .utf8),
              let date = try? JSONDecoder().decode(Date.self, from: data) else {
            return nil
        }
        self = date
    }

    public var rawValue: RawValue{
        guard let data = try? JSONEncoder().encode(self),
              let result = String(data:data,encoding: .utf8) else {
            return ""
        }
       return result
    }
}
func fenci(texts: String) -> String {
        var result = ""
        let tagger = NSLinguisticTagger(tagSchemes: [.tokenType], options: 0)
        let range = NSRange(location: 0, length: texts.utf16.count)
        let options: NSLinguisticTagger.Options = [.omitPunctuation, .omitWhitespace]
        tagger.string = texts.lowercased()
        tagger.enumerateTags(in: range, unit: .word, scheme: .tokenType, options: options) { tag, tokenRange, _ in
            let word = (texts as NSString).substring(with: tokenRange)
            result = result+"--"+word}
        return result
    }

 

//button扩展
struct RoundedButton: ViewModifier {
    func body(content: Content) -> some View {
        content
            .frame(maxWidth: .infinity, maxHeight: 20)
            .background(Color.blue.opacity(0.85))
            .cornerRadius(20)
            .font(.body)
            .multilineTextAlignment(.center)
            .foregroundColor(.white)
            .padding(.horizontal, 10)
    }
}
extension View {
    func roundedButtonStyle() -> some View {
        self.modifier(RoundedButton())
    }
}

 

 List{
                          Section(header: Text("Fruits"), footer: Text("\(gonggaos.count) fruits")) {
                            ForEach(gonggaos, id: \.self) { gonggao in
                                Label(gonggao.name, systemImage: "\(gonggaos.firstIndex(of: gonggao) ?? 0).circle.fill" )
                            }
                          }
                        }
                        .task{
                          loadData()
                        }

2022-07-22

func mlacc(){
        do {
            识别结果=""
            let mlModel = try AppleTagger(configuration: MLModelConfiguration()).model
            let customModel = try NLModel(mlModel: mlModel)
            let customTagScheme = NLTagScheme("Apple")
            let tagger = NLTagger(tagSchemes: [.nameType, customTagScheme])
            tagger.string = texts
            tagger.setModels([customModel], forTagScheme: customTagScheme)
            tagger.enumerateTags(in: texts.startIndex..<texts.endIndex, unit: .word,scheme: customTagScheme, options: .omitWhitespace) { tag, tokenRange  in
                if tag!.rawValue != "NONE" {
                    识别结果+="\(texts[tokenRange]): \(tag!.rawValue)\n"
                }
                return true
            }
        } catch {
            print(error)
        }
    }

 

posted @ 2022-07-22 22:03  速搞  阅读(54)  评论(0)    收藏  举报