diff --git a/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Dictionary.swift b/Sources/SwiftNLP/1. Data Collection/DurableHNSWCorpus + Dictionary.swift index d73152be76f5c2fcc878fa02d21de6b3a2a361bf..0f7bcd056fb74e886cc2b5735ff22e7a54504a9e 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 950ceaccbdc3e3471929c0d02f8b1d292396de05..c5ee27c982f56dd827e96241f5d0c8b2e499ba7d 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 e65ffe52a37b589369934844dc30922d3c363f98..bbef525b0cd66b655da15757826f76a719239e41 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 3aa1e8a8c0a954b6d0776dfd6a15898866d40045..9b35a02a34f947b96071a316aea01d06160bb21f 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 b5bc0eea3206d4b4c80d89bcd5c36244bf661c21..a4a9b3c04e62578d4bdf4f52d609a82a011ea042 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 489b4467d765fdbe46522b44d19bbdef25928d1d..1dd1e8a4a6b1fc8caa7c8ba93ad8aa3dd0c19650 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 0f3f4c68ee92c13805da3f5458adaca3e2c9eb98..e9670f71b295d37f8a5ba264b528caf80a3959d3 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 dbcde20d67c1d5e2e083b136064b76f59af18186..9982903291a49649bee88abff50001a31b8c9799 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 70678a58c8ec8a9981571deee4def309de9717ff..c2fb0d99f4887a4e9412abdc86597726351c9d6f 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 66b2f389593e0503d41a4aa4c988f0d3a4c17bdd..65d0384d58924f3f61658b29a2dd2abd17b4f073 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 cd5b319cab551c331b5064599553b25419d44081..8445929834592a51a2779a3cc89a31ef6ddca2a1 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 a6af8574d1cfeae396d260a8cfca0e3efb919c18..915e254a7bbf5213f0c1afe207efcea1a14ec546 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