Modernize repo
This commit is contained in:
parent
c5665914a2
commit
29ecb3077b
45
.github/workflows/docs.yml
vendored
Normal file
45
.github/workflows/docs.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Deploy Docs
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
Deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build Docs
|
||||
run: |
|
||||
xcrun xcodebuild docbuild \
|
||||
-scheme LevenshteinTransformations \
|
||||
-destination 'generic/platform=macOS' \
|
||||
-derivedDataPath "$PWD/.derivedData" \
|
||||
-skipPackagePluginValidation
|
||||
xcrun docc process-archive transform-for-static-hosting \
|
||||
"$PWD/.derivedData/Build/Products/Debug/LevenshteinTransformations.doccarchive" \
|
||||
--output-path "docs" \
|
||||
--hosting-base-path "LevenshteinTransformations"
|
||||
- name: Modify Docs
|
||||
run: |
|
||||
echo "<script>window.location.href += \"/documentation/levenshteintransformations\"</script>" > docs/index.html;
|
||||
sed -i '' 's/,2px/,10px/g' docs/css/index.038e887c.css
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: 'docs'
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@ -1,3 +0,0 @@
|
||||
# Contributors
|
||||
|
||||
- [david-swift](https://github.com/david-swift)
|
||||
@ -1,18 +0,0 @@
|
||||
# Reference Documentation
|
||||
|
||||
## Structs
|
||||
|
||||
- [Functions](structs/Functions.md)
|
||||
|
||||
## Enums
|
||||
|
||||
- [EditOperation](enums/EditOperation.md)
|
||||
- [LevenshteinTransformations](enums/LevenshteinTransformations.md)
|
||||
- [Transformation](enums/Transformation.md)
|
||||
|
||||
## Extensions
|
||||
|
||||
- [Array](extensions/Array.md)
|
||||
- [String](extensions/String.md)
|
||||
|
||||
This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs)
|
||||
@ -1,23 +0,0 @@
|
||||
**ENUM**
|
||||
|
||||
# `EditOperation`
|
||||
|
||||
An edit operation is a transformation without parameters.
|
||||
Additionally, it has the case `noChange`.
|
||||
|
||||
## Cases
|
||||
### `noChange`
|
||||
|
||||
No operation.
|
||||
|
||||
### `replace`
|
||||
|
||||
A replace operation.
|
||||
|
||||
### `delete`
|
||||
|
||||
A delete operation.
|
||||
|
||||
### `insert`
|
||||
|
||||
An insert operation.
|
||||
@ -1,32 +0,0 @@
|
||||
**ENUM**
|
||||
|
||||
# `LevenshteinTransformations`
|
||||
|
||||
The enumeration holding the transformation functions.
|
||||
|
||||
## Methods
|
||||
### `levenshteinTransformations(from:to:)`
|
||||
|
||||
The transformation function for arrays with equatable elements.
|
||||
- Parameters:
|
||||
- source: The original array.
|
||||
- target: The target array.
|
||||
- Returns: The required transformations.
|
||||
|
||||
### `setOperations(_:editDistances:source:target:)`
|
||||
|
||||
Set the operations and edit distances according to the source and target array.
|
||||
- Parameters:
|
||||
- operations: The operations.
|
||||
- editDistances: The edit distances.
|
||||
- source: The original array.
|
||||
- target: The target array.
|
||||
- Returns: The required transformations.
|
||||
|
||||
### `levenshteinTransformations(from:to:)`
|
||||
|
||||
The transformation function for arrays with identifiable elements.
|
||||
- Parameters:
|
||||
- source: The original array.
|
||||
- target: The target array.
|
||||
- Returns: The required transformations.
|
||||
@ -1,46 +0,0 @@
|
||||
**ENUM**
|
||||
|
||||
# `Transformation`
|
||||
|
||||
A transformation (replace, delete or insert).
|
||||
|
||||
## Cases
|
||||
### `replace(at:with:)`
|
||||
|
||||
Replace the element at a certain index with a certain element.
|
||||
|
||||
### `delete(at:)`
|
||||
|
||||
Delete the element at a certain index.
|
||||
|
||||
### `insert(at:element:)`
|
||||
|
||||
Insert a certain element at a certain index.
|
||||
|
||||
## Properties
|
||||
### `index`
|
||||
|
||||
The index at which is directly affected by the transformation.
|
||||
|
||||
### `element`
|
||||
|
||||
The element which is directly affected by the transformation.
|
||||
|
||||
## Methods
|
||||
### `description(source:)`
|
||||
|
||||
A description of the transformation.
|
||||
- Parameter source: The initial array.
|
||||
- Returns: The description.
|
||||
|
||||
### `log(source:)`
|
||||
|
||||
Print a description of the transformation.
|
||||
- Parameter source: The initial array.
|
||||
|
||||
### `transform(functions:nextTransformations:)`
|
||||
|
||||
Apply the transformation using a functions value.
|
||||
- Parameters:
|
||||
- functions: The functions value.
|
||||
- nextTransformations: All the following transformations for modifying the indices.
|
||||
@ -1,42 +0,0 @@
|
||||
**EXTENSION**
|
||||
|
||||
# `Array`
|
||||
|
||||
## Methods
|
||||
### `levenshteinDistance(to:)`
|
||||
|
||||
Calculate the Levenshtein distance to another array.
|
||||
- Parameter target: The target array.
|
||||
- Returns: The Levenshtein distance.
|
||||
|
||||
### `getTransformations(to:)`
|
||||
|
||||
Get the transformations needed to transform the array into the target array.
|
||||
- Parameter target: The target array.
|
||||
- Returns: The transformations.
|
||||
|
||||
### `transform(to:functions:)`
|
||||
|
||||
Call every transformation step needed to transform the array into the target array.
|
||||
- Parameters:
|
||||
- target: The target array.
|
||||
- functions: The transformation functions.
|
||||
|
||||
### `identifiableLevenshteinDistance(to:)`
|
||||
|
||||
Calculate the Levenshtein distance to another array.
|
||||
- Parameter target: The target array.
|
||||
- Returns: The Levenshtein distance.
|
||||
|
||||
### `identifiableGetTransformations(to:)`
|
||||
|
||||
Get the transformations needed to transform the array into the target array.
|
||||
- Parameter target: The target array.
|
||||
- Returns: The transformations.
|
||||
|
||||
### `identifiableTransform(to:functions:)`
|
||||
|
||||
Call every transformation step needed to transform the array into the target array.
|
||||
- Parameters:
|
||||
- target: The target array.
|
||||
- functions: The transformation functions.
|
||||
@ -1,23 +0,0 @@
|
||||
**EXTENSION**
|
||||
|
||||
# `String`
|
||||
|
||||
## Methods
|
||||
### `levenshteinDistance(to:)`
|
||||
|
||||
Calculate the Levenshtein distance to another string.
|
||||
- Parameter target: The target string.
|
||||
- Returns: The Levenshtein distance.
|
||||
|
||||
### `getTransformations(to:)`
|
||||
|
||||
Get the transformations needed to transform the string into the target string.
|
||||
- Parameter target: The target string.
|
||||
- Returns: The transformations.
|
||||
|
||||
### `transform(to:functions:)`
|
||||
|
||||
Call every transformation step needed to transform the string into the target string.
|
||||
- Parameters:
|
||||
- target: The target string.
|
||||
- functions: The transformation functions.
|
||||
@ -1,27 +0,0 @@
|
||||
**STRUCT**
|
||||
|
||||
# `Functions`
|
||||
|
||||
The replace, delete and insert functions type.
|
||||
|
||||
## Properties
|
||||
### `replace`
|
||||
|
||||
The replace function.
|
||||
|
||||
### `delete`
|
||||
|
||||
The delete function.
|
||||
|
||||
### `insert`
|
||||
|
||||
The insert function.
|
||||
|
||||
## Methods
|
||||
### `init(replace:delete:insert:)`
|
||||
|
||||
Initialize a functions value.
|
||||
- Parameters:
|
||||
- replace: Replace the element at a certain index with a certain element.
|
||||
- delete: Delete the element at a certain index.
|
||||
- insert: Insert a certain element at a certain index.
|
||||
5
Makefile
5
Makefile
@ -1,5 +0,0 @@
|
||||
docs:
|
||||
@sourcedocs generate --min-acl private -r --spm-module LevenshteinTransformations
|
||||
|
||||
swiftlint:
|
||||
@swiftlint --autocorrect
|
||||
65
README.md
65
README.md
@ -4,12 +4,12 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/david-swift/LevenshteinTransformations">
|
||||
GitHub
|
||||
<a href=“https://david-swift.github.io/LevenshteinTransformations">
|
||||
Documentation
|
||||
</a>
|
||||
·
|
||||
<a href="Documentation/Reference/README.md">
|
||||
Contributor Docs
|
||||
<a href="https://github.com/david-swift/LevenshteinTransformations">
|
||||
GitHub
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@ -32,65 +32,10 @@ Transform an array into any other array of the same type, or a string into any o
|
||||
|
||||
## Usage
|
||||
|
||||
```swift
|
||||
let source = [1, 2, 5, 6]
|
||||
let target = [0, 1, 5, 6, 10]
|
||||
```
|
||||
|
||||
There are three functions available for arrays containing elements conforming to `Equatable` and strings.
|
||||
|
||||
### Arrays with `Equatable` Elements and Strings
|
||||
|
||||
#### Levenshtein Distance
|
||||
Get the Levenshtein distance with `levenshteinDistance(to:)`:
|
||||
```swift
|
||||
print(source.levenshteinDistance(to: target))
|
||||
```
|
||||
This example outputs `3`.
|
||||
|
||||
#### Transformation Steps
|
||||
Get the individual transformation steps with `getTransformations(to:)`.
|
||||
```swift
|
||||
print(source.getTransformations(to: target).map { $0.description(source: source) }.joined(separator: "\n"))
|
||||
```
|
||||
This example prints the descriptions of the transformations:
|
||||
```
|
||||
Replace '1' at position 0 with '0'
|
||||
Replace '2' at position 1 with '1'
|
||||
Insert '10' at position 4
|
||||
```
|
||||
|
||||
#### Run Functions for the Steps
|
||||
Directly run functions for the `replace`, `delete` and `insert` transformations using the `transform(to:functions:)` function.
|
||||
```swift
|
||||
var modified = source
|
||||
|
||||
source.transform(
|
||||
to: target,
|
||||
functions: .init { index, element in
|
||||
modified[index] = element
|
||||
} delete: { index in
|
||||
modified.remove(at: index)
|
||||
} insert: { index, element in
|
||||
modified.insert(element, at: index)
|
||||
}
|
||||
)
|
||||
|
||||
print(modified == target)
|
||||
```
|
||||
This example outputs `true`.
|
||||
|
||||
### Arrays with `Identifiable` Elements
|
||||
|
||||
The same functions are available for arrays with identifiable elements, but they are named differently to avoid conflicts:
|
||||
- `identifiableLevenshteinDistance(to:)`
|
||||
- `identifiableGetTransformations(to:)`
|
||||
- `identifiableTransform(to:functions:)`
|
||||
Read the [Getting Started](https://david-swift.github.io/LevenshteinTransformations/documentation/levenshteintransformations/gettingstarted) article to learn how to use this package.
|
||||
|
||||
## Thanks
|
||||
|
||||
- The [contributors](Contributors.md)
|
||||
- [SwiftLint](https://github.com/realm/SwiftLint) for checking whether code style conventions are violated
|
||||
- The programming language [Swift](https://github.com/apple/swift)
|
||||
- [SourceDocs](https://github.com/SourceDocs/SourceDocs) used for generating the [docs](Documentation/Reference/README.md)
|
||||
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
# Getting started
|
||||
|
||||
Learn how to use _Levenshtein Transformations_.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Open your Swift package in GNOME Builder, Xcode, or any other IDE.
|
||||
2. Open the `Package.swift` file.
|
||||
3. Into the `Package` initializer, under `dependencies`, paste:
|
||||
```swift
|
||||
.package(url: "https://github.com/david-swift/LevenshteinTransformations", from: "0.1.0")
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```swift
|
||||
let source = [1, 2, 5, 6]
|
||||
let target = [0, 1, 5, 6, 10]
|
||||
```
|
||||
|
||||
There are three functions available for arrays containing elements conforming to `Equatable` and strings.
|
||||
|
||||
### Arrays with Equatable Elements and Strings
|
||||
|
||||
#### Levenshtein Distance
|
||||
Get the Levenshtein distance with ``Swift/Array/levenshteinDistance(to:)`` (for strings: ``Swift/String/levenshteinDistance(to:)``).
|
||||
```swift
|
||||
print(source.levenshteinDistance(to: target))
|
||||
```
|
||||
This example outputs `3`.
|
||||
|
||||
#### Transformation Steps
|
||||
Get the individual transformation steps with ``Swift/Array/getTransformations(to:)`` (for strings: ``Swift/String/getTransformations(to:)``).
|
||||
```swift
|
||||
print(source.getTransformations(to: target).map { $0.description(source: source) }.joined(separator: "\n"))
|
||||
```
|
||||
This example prints the descriptions of the transformations:
|
||||
```
|
||||
Replace '1' at position 0 with '0'
|
||||
Replace '2' at position 1 with '1'
|
||||
Insert '10' at position 4
|
||||
```
|
||||
|
||||
#### Run Functions for the Steps
|
||||
Directly run functions for the `replace`, `delete` and `insert` transformations using the ``Swift/Array/transform(to:functions:)`` (for strings: ``Swift/String/transform(to:functions:)``) function.
|
||||
```swift
|
||||
var modified = source
|
||||
|
||||
source.transform(
|
||||
to: target,
|
||||
functions: .init { index, element in
|
||||
modified[index] = element
|
||||
} delete: { index in
|
||||
modified.remove(at: index)
|
||||
} insert: { index, element in
|
||||
modified.insert(element, at: index)
|
||||
}
|
||||
)
|
||||
|
||||
print(modified == target)
|
||||
```
|
||||
This example outputs `true`.
|
||||
|
||||
### Arrays with Identifiable Elements
|
||||
|
||||
The same functions are available for arrays with identifiable elements, but they are named differently to avoid conflicts:
|
||||
- ``Swift/Array/identifiableLevenshteinDistance(to:)``
|
||||
- ``Swift/Array/identifiableGetTransformations(to:)``
|
||||
- ``Swift/Array/identifiableTransform(to:functions:)``
|
||||
|
||||
## Development
|
||||
_Levenshtein Transformations_ is an open source project. Visit the [GitHub repository][1] for bug reports, feature requests, pull requests and more information.
|
||||
|
||||
[1]: https://github.com/david-swift/LevenshteinTransformations
|
||||
@ -0,0 +1,9 @@
|
||||
# ``LevenshteinTransformations``
|
||||
|
||||
_Levenshtein Transformations_ allows transforming one array into another array, or a string into another string, using only the three transformations `replace`, `delete`, and `insert`.
|
||||
|
||||
## Topics
|
||||
|
||||
### Articles
|
||||
|
||||
- <doc:GettingStarted>
|
||||
@ -0,0 +1,31 @@
|
||||
{
|
||||
"theme": {
|
||||
"border-radius": "10px",
|
||||
"button": {
|
||||
"border-radius": "20px"
|
||||
},
|
||||
"color": {
|
||||
"button-background": "#3490EC",
|
||||
"button-background-active": "#3490EC",
|
||||
"button-background-hover": "#5688FD",
|
||||
"button-text": "#ffffff",
|
||||
"header": "#323F80",
|
||||
"documentation-intro-accent": "var(--color-header)",
|
||||
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-header) 30%, #000 100%)",
|
||||
"link": "#3490EC",
|
||||
"nav-link-color": "#3490EC",
|
||||
"nav-dark-link-color": "#3490EC",
|
||||
"tabnav-item-border-color": "#3490EC",
|
||||
"fill-light-blue-secondary": "#3490EC",
|
||||
"fill-blue": "#3490EC",
|
||||
"figure-blue": "#3490EC",
|
||||
"standard-blue-documentation-intro-fill": "#3490EC",
|
||||
"figure-blue": "#3490EC",
|
||||
"navigator-item-hover": {
|
||||
"light": "#3490EC15",
|
||||
"dark": "#2B466F"
|
||||
}
|
||||
},
|
||||
"additionalProperties": "#3490EC"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user