From 6e091f987f78bbf60b20e87d905d1da69f7983ab Mon Sep 17 00:00:00 2001 From: Mingchung Xia <mingchung.xia@gmail.com> Date: Sat, 16 Mar 2024 17:12:53 -0400 Subject: [PATCH] Added license and docs --- .../DurableHNSWCorpus + Dictionary.swift | 23 +++++++++++- .../DurableHNSWCorpus + File IO.swift | 23 +++++++++++- .../DurableHNSWCorpus + Sequence.swift | 25 +++++++++++-- .../DurableHNSWCorpus.swift | 23 +++++++++++- .../EphemeralHNSWCorpus + Codable.swift | 23 +++++++++++- .../EphemeralHNSWCorpus + Dictionary.swift | 23 +++++++++++- .../EphemeralHNSWCorpus + Sequence.swift | 3 ++ .../EphemeralHNSWCorpus.swift | 3 ++ .../HNSW/CartesianDistanceMetric.swift | 8 ++-- .../HNSW/CosineSimilarityMetric.swift | 37 ++++++++++++++----- ...nisticEphemeralVectorIndex + Codable.swift | 23 +++++++++++- .../HNSW/HNSWCorpusDataHandler.swift | 25 +++++++++++-- 12 files changed, 207 insertions(+), 32 deletions(-) diff --git a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Dictionary.swift b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Dictionary.swift index d73152be..0f7bcd05 100644 --- a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Dictionary.swift +++ b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Dictionary.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// HNSWCorpus + Dictionary.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-02-26. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-26. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + File IO.swift b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + File IO.swift index 950ceacc..c5ee27c9 100644 --- a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + File IO.swift +++ b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + File IO.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// DurableHNSWCorpus + File IO.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-03-12. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-03-12. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Sequence.swift b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Sequence.swift index e65ffe52..bbef525b 100644 --- a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Sequence.swift +++ b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Sequence.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// DurableHNSWCorpus + Sequence.swift -// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // -// Created by Mingchung Xia on 2024-03-16. +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-03-16. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus.swift b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus.swift index 3aa1e8a8..9b35a02a 100644 --- a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus.swift +++ b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// DurableHNSWCorpus.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-02-26. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-26. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Codable.swift b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Codable.swift index b5bc0eea..a4a9b3c0 100644 --- a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Codable.swift +++ b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Codable.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// HNSWCorpus + Codable.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-02-07. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-07. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Dictionary.swift b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Dictionary.swift index 489b4467..1dd1e8a4 100644 --- a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Dictionary.swift +++ b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Dictionary.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// HNSWCorpus + Dictionary.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-02-14. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-14. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Sequence.swift b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Sequence.swift index 0f3f4c68..e9670f71 100644 --- a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Sequence.swift +++ b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus + Sequence.swift @@ -20,6 +20,9 @@ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-14. +// import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus.swift b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus.swift index dbcde20d..99829032 100644 --- a/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus.swift +++ b/Sources/SwiftNLP/1. Data Collection/EphemeralHNSWCorpus.swift @@ -20,6 +20,9 @@ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-14. +// import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/HNSW/CartesianDistanceMetric.swift b/Sources/SwiftNLP/1. Data Collection/HNSW/CartesianDistanceMetric.swift index 70678a58..c2fb0d99 100644 --- a/Sources/SwiftNLP/1. Data Collection/HNSW/CartesianDistanceMetric.swift +++ b/Sources/SwiftNLP/1. Data Collection/HNSW/CartesianDistanceMetric.swift @@ -28,9 +28,8 @@ import Foundation import SimilarityMetric #if canImport(Surge) && canImport(Accelerate) && os(macOS) - -import Accelerate import Surge +import Accelerate public struct CartesianDistanceMetric<Vector: Collection & Codable>: SimilarityMetric where Vector.Element: BinaryFloatingPoint { public func similarity(between someItem: Vector, _ otherItem: Vector) -> Vector.Element { @@ -39,9 +38,10 @@ public struct CartesianDistanceMetric<Vector: Collection & Codable>: SimilarityM } #else +// TODO: Import using Nifty (currently unable to fetch package dependency) +// import Nifty -// This may be less efficient on Linux - +/// This implementation may be less efficient on Linux public struct CartesianDistanceMetric<Vector: Collection & Codable>: SimilarityMetric where Vector.Element: BinaryFloatingPoint { public func similarity(between someItem: Vector, _ otherItem: Vector) -> Vector.Element { return someItem.enumerated().reduce(0) { result, item in diff --git a/Sources/SwiftNLP/1. Data Collection/HNSW/CosineSimilarityMetric.swift b/Sources/SwiftNLP/1. Data Collection/HNSW/CosineSimilarityMetric.swift index 66b2f389..65d0384d 100644 --- a/Sources/SwiftNLP/1. Data Collection/HNSW/CosineSimilarityMetric.swift +++ b/Sources/SwiftNLP/1. Data Collection/HNSW/CosineSimilarityMetric.swift @@ -1,19 +1,35 @@ +// Copyright (c) 2024 Jim Wallace // -// CosineSimilarityMetric.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-03-14. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-03-14. // - -#if canImport(Surge) && canImport(Accelerate) && os(macOS) import Foundation -import Accelerate import SimilarityMetric -import Surge -// MARK: May be improved on using Surge/Nifty -// See https://developer.apple.com/documentation/accelerate/vdsp-snv +#if canImport(Surge) && canImport(Accelerate) && os(macOS) +import Surge +import Accelerate public struct CosineSimilarityMetric<Vector: Collection & Codable>: SimilarityMetric where Vector.Element: BinaryFloatingPoint { public func similarity(between someItem: Vector, _ otherItem: Vector) -> Vector.Element { @@ -37,9 +53,10 @@ public struct CosineSimilarityMetric<Vector: Collection & Codable>: SimilarityMe } #else +// TODO: Import using Nifty (currently unable to fetch package dependency) +// import Nifty -// This may be less efficient on Linux - +/// This implementation may be less efficient on Linux public struct CosineSimilarityMetric<Vector: Collection & Codable>: SimilarityMetric where Vector.Element: BinaryFloatingPoint { public func similarity(between someItem: Vector, _ otherItem: Vector) -> Vector.Element { let dotProduct = zip(someItem, otherItem).reduce(0) { $0 + $1.0 * $1.1 } diff --git a/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift b/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift index cd5b319c..84459298 100644 --- a/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift +++ b/Sources/SwiftNLP/1. Data Collection/HNSW/DeterministicEphemeralVectorIndex + Codable.swift @@ -1,8 +1,27 @@ +// Copyright (c) 2024 Jim Wallace // -// DeterministicEphemeralVectorIndex + Codable.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-02-07. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-07. // import Foundation diff --git a/Sources/SwiftNLP/1. Data Collection/HNSW/HNSWCorpusDataHandler.swift b/Sources/SwiftNLP/1. Data Collection/HNSW/HNSWCorpusDataHandler.swift index a6af8574..915e254a 100644 --- a/Sources/SwiftNLP/1. Data Collection/HNSW/HNSWCorpusDataHandler.swift +++ b/Sources/SwiftNLP/1. Data Collection/HNSW/HNSWCorpusDataHandler.swift @@ -1,11 +1,30 @@ +// Copyright (c) 2024 Jim Wallace // -// HNSWCorpusDataHandler.swift +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: // +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// Created by Mingchung Xia on 2024-02-13. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// Created by Mingchung Xia on 2024-02-13. // -// This is outdated since we now have the presence of a DurableHNSWCorpus but still available for reference +// MARK: This is outdated since we now have the presence of a DurableHNSWCorpus but still available for reference import Foundation -- GitLab