From ebc99497058404e5619bf4373f60834507bc7f09 Mon Sep 17 00:00:00 2001 From: Bracken Spencer Date: Sat, 29 Jun 2019 22:40:11 +0200 Subject: [PATCH] Refreshed commit --- .gitattributes | 7 + .gitignore | 24 + .gitmodules | 3 + LICENSE | 21 + README.md | 52 ++ .../project.pbxproj | 538 ++++++++++++++++++ .../Base.lproj/Main.storyboard | 184 ++++++ .../Classes/AppDelegate.h | 15 + .../Classes/AppDelegate.m | 17 + .../Classes/ViewController.h | 13 + .../Classes/ViewController.m | 72 +++ .../AppIcon.appiconset/Contents.json | 53 ++ .../LaunchImage.launchimage/Contents.json | 9 + .../Info.plist | 36 ++ .../Readability-Objective-C Example/main.m | 17 + .../Info.plist | 24 + .../Readability_Objective_C_ExampleTests.m | 182 ++++++ Readability/Readability+NSNumber.h | 15 + Readability/Readability+NSNumber.m | 25 + Readability/Readability+NSString.h | 24 + Readability/Readability+NSString.m | 132 +++++ Readability/Readability.h | 27 + Readability/Readability.m | 211 +++++++ Readability/objC-syllable-counter | 1 + _config.yml | 1 + 25 files changed, 1703 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example.xcodeproj/project.pbxproj create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Base.lproj/Main.storyboard create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.h create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.m create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.h create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.m create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/LaunchImage.launchimage/Contents.json create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/Info.plist create mode 100644 Readability-Objective-C Example/Readability-Objective-C Example/main.m create mode 100644 Readability-Objective-C Example/Readability-Objective-C ExampleTests/Info.plist create mode 100644 Readability-Objective-C Example/Readability-Objective-C ExampleTests/Readability_Objective_C_ExampleTests.m create mode 100644 Readability/Readability+NSNumber.h create mode 100644 Readability/Readability+NSNumber.m create mode 100644 Readability/Readability+NSString.h create mode 100644 Readability/Readability+NSString.m create mode 100644 Readability/Readability.h create mode 100644 Readability/Readability.m create mode 160000 Readability/objC-syllable-counter create mode 100644 _config.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c8564cc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +*.pbxproj -crlf -diff -merge +*.xib -crlf -diff -merge +*.nib -crlf -diff -merge + +# Disable line ending conversions for all files +* -text + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc31b76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.DS_Store +.Trashes +*.swp +*.lock +profile +*~.nib +DerivedData/ +build/ +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 +*.moved-aside +Pods/ +Podfile.lock +*.xcuserstate +.idea/ +xcuserdata/ +project.xcworkspace/ +xcuserdata/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..eef2785 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Readability/objC-syllable-counter"] + path = Readability/objC-syllable-counter + url = https://github.com/brackendev/objC-syllable-counter.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3035f58 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2014-2019 brackendev + +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. + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..85bdc6c --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +Readability-Objective-C +======================= +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d9b21f69a0c54ee08897e745e6285443)](https://www.codacy.com/app/brackendev/Readability-Objective-C?utm_source=github.com&utm_medium=referral&utm_content=brackendev/Readability-Objective-C&utm_campaign=Badge_Grade) + +**Metrics to determine readability and comprehension difficulty for contemporary English text.** + +* [iOS](https://en.wikipedia.org/wiki/IOS) reference platform. +* Example app and tests included. + +## Installation + +Git clone this repository. [objC-syllable-counter](https://github.com/brackendev/objC-syllable-counter.git) submodule is required, so be sure to clone like this: + +````bash +git clone --recursive https://github.com/brackendev/Readability-Objective-C.git +```` + +## Metrics Included + +* [Automated Readability Index](http://en.wikipedia.org/wiki/Automated_Readability_Index) +* [Coleman–Liau Index](http://en.wikipedia.org/wiki/Coleman–Liau_index) +* [Flesch-Kincaid Grade Level](http://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests) +* [Flesch Reading Ease](http://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests) +* [Gunning Fog Index](http://en.wikipedia.org/wiki/Gunning_fog_index) +* [SMOG Grade](http://en.wikipedia.org/wiki/SMOG) + +## Usage + +See the [view controller](https://github.com/brackendev/Readability-Objective-C/blob/master/Readability-Objective-C%20Example/Readability-Objective-C%20Example/Classes/ViewController.m) in the example app. + +## Ports + +* [Pharo](http://brackendev.github.io/Readability-Pharo/) +* [Swift](http://brackendev.github.io/Readability-Swift/) +* [VisualWorks](https://brackendev.github.io/Readability-VisualWorks/) + +## Acknowledgements + +* [E.A. Smith, EdD and R.J. Senter, PhD](https://apps.dtic.mil/dtic/tr/fulltext/u2/667273.pdf), for the [Automated Readability Index](http://en.wikipedia.org/wiki/Automated_Readability_Index). +* [Meri Coleman and T.L. Liau](https://psycnet.apa.org/record/1975-22007-001) for the [Coleman–Liau Index](http://en.wikipedia.org/wiki/Coleman–Liau_index). +* [Rudolf Flesch](https://en.wikipedia.org/wiki/Rudolf_Flesch) and [J. Peter Kincaid](https://en.wikipedia.org/wiki/J._Peter_Kincaid) for the [Flesch-Kincaid Grade Level](http://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests). +* [Rudolf Flesch](https://en.wikipedia.org/wiki/Rudolf_Flesch) for the [Flesch Reading Ease](https://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests#Flesch_reading_ease). +* Robert Gunning for the [Gunning Fog Index](http://en.wikipedia.org/wiki/Gunning_fog_index). +* [G. Harry McLaughlin](https://ogg.osu.edu/media/documents/health_lit/WRRSMOG_Readability_Formula_G._Harry_McLaughlin__1969_.pdf) for the [SMOG Grade](http://en.wikipedia.org/wiki/SMOG). + +## Author + +[brackendev](https://www.github.com/brackendev) + +## License + +Readability-Objective-C is released under the MIT license. See the LICENSE file for more info. diff --git a/Readability-Objective-C Example/Readability-Objective-C Example.xcodeproj/project.pbxproj b/Readability-Objective-C Example/Readability-Objective-C Example.xcodeproj/project.pbxproj new file mode 100644 index 0000000..8cb828c --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example.xcodeproj/project.pbxproj @@ -0,0 +1,538 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + C915919A1B289427000AEAAB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C91591961B289427000AEAAB /* AppDelegate.m */; }; + C915919C1B289427000AEAAB /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C91591981B289427000AEAAB /* ViewController.m */; }; + C940358719E9880300388A4B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C940358619E9880300388A4B /* main.m */; }; + C940359019E9880300388A4B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C940358E19E9880300388A4B /* Main.storyboard */; }; + C940359219E9880300388A4B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C940359119E9880300388A4B /* Images.xcassets */; }; + C94035A119E9880300388A4B /* Readability_Objective_C_ExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C94035A019E9880300388A4B /* Readability_Objective_C_ExampleTests.m */; }; + C971235220390CF700DF121E /* Readability+NSString.m in Sources */ = {isa = PBXBuildFile; fileRef = C971235120390CF700DF121E /* Readability+NSString.m */; }; + C971235320390CF700DF121E /* Readability+NSString.m in Sources */ = {isa = PBXBuildFile; fileRef = C971235120390CF700DF121E /* Readability+NSString.m */; }; + C97123562039195C00DF121E /* Readability+NSNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = C97123542039195C00DF121E /* Readability+NSNumber.m */; }; + C97123572039195C00DF121E /* Readability+NSNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = C97123542039195C00DF121E /* Readability+NSNumber.m */; }; + C9F5A68519EC5C1600F85CC7 /* Readability.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F5A68219EC5C1600F85CC7 /* Readability.m */; }; + C9F5A68619EC5C1600F85CC7 /* Readability.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F5A68219EC5C1600F85CC7 /* Readability.m */; }; + C9F5A69219EC66F700F85CC7 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F5A68B19EC66F700F85CC7 /* RegexKitLite.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc -w"; }; }; + C9F5A69319EC66F700F85CC7 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F5A68B19EC66F700F85CC7 /* RegexKitLite.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc -w"; }; }; + C9F5A69619EC66F700F85CC7 /* SyllableCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F5A68D19EC66F700F85CC7 /* SyllableCounter.m */; }; + C9F5A69719EC66F700F85CC7 /* SyllableCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F5A68D19EC66F700F85CC7 /* SyllableCounter.m */; }; + C9F5A69919EC670100F85CC7 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C9F5A69819EC670100F85CC7 /* libicucore.dylib */; }; + C9F5A69A19EC671800F85CC7 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C9F5A69819EC670100F85CC7 /* libicucore.dylib */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + C940359B19E9880300388A4B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C940357919E9880300388A4B /* Project object */; + proxyType = 1; + remoteGlobalIDString = C940358019E9880300388A4B; + remoteInfo = "Readability-iOS Example"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + C91591951B289427000AEAAB /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + C91591961B289427000AEAAB /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + C91591971B289427000AEAAB /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + C91591981B289427000AEAAB /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + C940358119E9880300388A4B /* Readability-Objective-C Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Readability-Objective-C Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + C940358519E9880300388A4B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.info; path = Info.plist; sourceTree = ""; }; + C940358619E9880300388A4B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + C940358F19E9880300388A4B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + C940359119E9880300388A4B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + C940359A19E9880300388A4B /* Readability-Objective-C ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Readability-Objective-C ExampleTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + C940359F19E9880300388A4B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.info; path = Info.plist; sourceTree = ""; }; + C94035A019E9880300388A4B /* Readability_Objective_C_ExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Readability_Objective_C_ExampleTests.m; sourceTree = ""; }; + C971235020390CF700DF121E /* Readability+NSString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Readability+NSString.h"; sourceTree = ""; }; + C971235120390CF700DF121E /* Readability+NSString.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "Readability+NSString.m"; sourceTree = ""; }; + C97123542039195C00DF121E /* Readability+NSNumber.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Readability+NSNumber.m"; sourceTree = ""; }; + C97123552039195C00DF121E /* Readability+NSNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Readability+NSNumber.h"; sourceTree = ""; }; + C9F5A5C419EB0B5E00F85CC7 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; + C9F5A5C619EB0BB400F85CC7 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; + C9F5A68119EC5C1600F85CC7 /* Readability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.objj.h; path = Readability.h; sourceTree = ""; }; + C9F5A68219EC5C1600F85CC7 /* Readability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Readability.m; sourceTree = ""; }; + C9F5A68A19EC66F700F85CC7 /* RegexKitLite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.objj.h; path = RegexKitLite.h; sourceTree = ""; }; + C9F5A68B19EC66F700F85CC7 /* RegexKitLite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegexKitLite.m; sourceTree = ""; }; + C9F5A68C19EC66F700F85CC7 /* SyllableCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.objj.h; path = SyllableCounter.h; sourceTree = ""; }; + C9F5A68D19EC66F700F85CC7 /* SyllableCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SyllableCounter.m; sourceTree = ""; }; + C9F5A69819EC670100F85CC7 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + C940357E19E9880300388A4B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C9F5A69919EC670100F85CC7 /* libicucore.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C940359719E9880300388A4B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C9F5A69A19EC671800F85CC7 /* libicucore.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C91591941B289427000AEAAB /* Classes */ = { + isa = PBXGroup; + children = ( + C91591951B289427000AEAAB /* AppDelegate.h */, + C91591961B289427000AEAAB /* AppDelegate.m */, + C91591971B289427000AEAAB /* ViewController.h */, + C91591981B289427000AEAAB /* ViewController.m */, + ); + path = Classes; + sourceTree = ""; + }; + C940357819E9880300388A4B = { + isa = PBXGroup; + children = ( + C9F5A5C419EB0B5E00F85CC7 /* LICENSE */, + C9F5A5C619EB0BB400F85CC7 /* README.md */, + C940358219E9880300388A4B /* Products */, + C9F5A68019EC5C1600F85CC7 /* Readability */, + C940358319E9880300388A4B /* Readability-Objective-C Example */, + C940359D19E9880300388A4B /* Readability-Objective-C ExampleTests */, + ); + sourceTree = ""; + }; + C940358219E9880300388A4B /* Products */ = { + isa = PBXGroup; + children = ( + C940358119E9880300388A4B /* Readability-Objective-C Example.app */, + C940359A19E9880300388A4B /* Readability-Objective-C ExampleTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + C940358319E9880300388A4B /* Readability-Objective-C Example */ = { + isa = PBXGroup; + children = ( + C91591941B289427000AEAAB /* Classes */, + C940359119E9880300388A4B /* Images.xcassets */, + C940358E19E9880300388A4B /* Main.storyboard */, + C940358419E9880300388A4B /* Supporting Files */, + ); + path = "Readability-Objective-C Example"; + sourceTree = ""; + }; + C940358419E9880300388A4B /* Supporting Files */ = { + isa = PBXGroup; + children = ( + C940358519E9880300388A4B /* Info.plist */, + C940358619E9880300388A4B /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + C940359D19E9880300388A4B /* Readability-Objective-C ExampleTests */ = { + isa = PBXGroup; + children = ( + C94035A019E9880300388A4B /* Readability_Objective_C_ExampleTests.m */, + C940359E19E9880300388A4B /* Supporting Files */, + ); + path = "Readability-Objective-C ExampleTests"; + sourceTree = ""; + }; + C940359E19E9880300388A4B /* Supporting Files */ = { + isa = PBXGroup; + children = ( + C940359F19E9880300388A4B /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + C9F5A68019EC5C1600F85CC7 /* Readability */ = { + isa = PBXGroup; + children = ( + C9F5A68719EC66F700F85CC7 /* objC-syllable-counter */, + C9F5A68119EC5C1600F85CC7 /* Readability.h */, + C9F5A68219EC5C1600F85CC7 /* Readability.m */, + C97123552039195C00DF121E /* Readability+NSNumber.h */, + C97123542039195C00DF121E /* Readability+NSNumber.m */, + C971235020390CF700DF121E /* Readability+NSString.h */, + C971235120390CF700DF121E /* Readability+NSString.m */, + ); + name = Readability; + path = ../Readability; + sourceTree = ""; + }; + C9F5A68719EC66F700F85CC7 /* objC-syllable-counter */ = { + isa = PBXGroup; + children = ( + C9F5A69819EC670100F85CC7 /* libicucore.dylib */, + C9F5A68919EC66F700F85CC7 /* RegexKitLite */, + C9F5A68C19EC66F700F85CC7 /* SyllableCounter.h */, + C9F5A68D19EC66F700F85CC7 /* SyllableCounter.m */, + ); + path = "objC-syllable-counter"; + sourceTree = ""; + }; + C9F5A68919EC66F700F85CC7 /* RegexKitLite */ = { + isa = PBXGroup; + children = ( + C9F5A68A19EC66F700F85CC7 /* RegexKitLite.h */, + C9F5A68B19EC66F700F85CC7 /* RegexKitLite.m */, + ); + path = RegexKitLite; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + C940358019E9880300388A4B /* Readability-Objective-C Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = C94035A419E9880300388A4B /* Build configuration list for PBXNativeTarget "Readability-Objective-C Example" */; + buildPhases = ( + C940357D19E9880300388A4B /* Sources */, + C940357E19E9880300388A4B /* Frameworks */, + C940357F19E9880300388A4B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Readability-Objective-C Example"; + productName = "Readability-iOS Example"; + productReference = C940358119E9880300388A4B /* Readability-Objective-C Example.app */; + productType = "com.apple.product-type.application"; + }; + C940359919E9880300388A4B /* Readability-Objective-C ExampleTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = C94035A719E9880300388A4B /* Build configuration list for PBXNativeTarget "Readability-Objective-C ExampleTests" */; + buildPhases = ( + C940359619E9880300388A4B /* Sources */, + C940359719E9880300388A4B /* Frameworks */, + C940359819E9880300388A4B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + C940359C19E9880300388A4B /* PBXTargetDependency */, + ); + name = "Readability-Objective-C ExampleTests"; + productName = "Readability-iOS ExampleTests"; + productReference = C940359A19E9880300388A4B /* Readability-Objective-C ExampleTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C940357919E9880300388A4B /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = "brackendev"; + TargetAttributes = { + C940358019E9880300388A4B = { + CreatedOnToolsVersion = 6.0.1; + ProvisioningStyle = Manual; + }; + C940359919E9880300388A4B = { + CreatedOnToolsVersion = 6.0.1; + TestTargetID = C940358019E9880300388A4B; + }; + }; + }; + buildConfigurationList = C940357C19E9880300388A4B /* Build configuration list for PBXProject "Readability-Objective-C Example" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = C940357819E9880300388A4B; + productRefGroup = C940358219E9880300388A4B /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C940358019E9880300388A4B /* Readability-Objective-C Example */, + C940359919E9880300388A4B /* Readability-Objective-C ExampleTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + C940357F19E9880300388A4B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C940359019E9880300388A4B /* Main.storyboard in Resources */, + C940359219E9880300388A4B /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C940359819E9880300388A4B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + C940357D19E9880300388A4B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C971235220390CF700DF121E /* Readability+NSString.m in Sources */, + C9F5A68519EC5C1600F85CC7 /* Readability.m in Sources */, + C9F5A69619EC66F700F85CC7 /* SyllableCounter.m in Sources */, + C9F5A69219EC66F700F85CC7 /* RegexKitLite.m in Sources */, + C915919C1B289427000AEAAB /* ViewController.m in Sources */, + C97123562039195C00DF121E /* Readability+NSNumber.m in Sources */, + C915919A1B289427000AEAAB /* AppDelegate.m in Sources */, + C940358719E9880300388A4B /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C940359619E9880300388A4B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C971235320390CF700DF121E /* Readability+NSString.m in Sources */, + C9F5A69319EC66F700F85CC7 /* RegexKitLite.m in Sources */, + C94035A119E9880300388A4B /* Readability_Objective_C_ExampleTests.m in Sources */, + C97123572039195C00DF121E /* Readability+NSNumber.m in Sources */, + C9F5A68619EC5C1600F85CC7 /* Readability.m in Sources */, + C9F5A69719EC66F700F85CC7 /* SyllableCounter.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + C940359C19E9880300388A4B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C940358019E9880300388A4B /* Readability-Objective-C Example */; + targetProxy = C940359B19E9880300388A4B /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + C940358E19E9880300388A4B /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + C940358F19E9880300388A4B /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + C94035A219E9880300388A4B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + C94035A319E9880300388A4B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + C94035A519E9880300388A4B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Manual; + DEVELOPMENT_TEAM = ""; + INFOPLIST_FILE = "Readability-Objective-C Example/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "dk.mmw.Readability-Objective-C-Example"; + PRODUCT_NAME = "Readability-Objective-C Example"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "Readability-Objective-C Example-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + C94035A619E9880300388A4B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Manual; + DEVELOPMENT_TEAM = ""; + INFOPLIST_FILE = "Readability-Objective-C Example/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "dk.mmw.Readability-Objective-C-Example"; + PRODUCT_NAME = "Readability-Objective-C Example"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "Readability-Objective-C Example-Bridging-Header.h"; + }; + name = Release; + }; + C94035A819E9880300388A4B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + INFOPLIST_FILE = "Readability-Objective-C ExampleTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.modernmobileworks.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "Readability-Objective-C ExampleTests"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Readability-Objective-C Example.app/Readability-Objective-C Example"; + }; + name = Debug; + }; + C94035A919E9880300388A4B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + INFOPLIST_FILE = "Readability-Objective-C ExampleTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.modernmobileworks.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "Readability-Objective-C ExampleTests"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Readability-Objective-C Example.app/Readability-Objective-C Example"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C940357C19E9880300388A4B /* Build configuration list for PBXProject "Readability-Objective-C Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C94035A219E9880300388A4B /* Debug */, + C94035A319E9880300388A4B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C94035A419E9880300388A4B /* Build configuration list for PBXNativeTarget "Readability-Objective-C Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C94035A519E9880300388A4B /* Debug */, + C94035A619E9880300388A4B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C94035A719E9880300388A4B /* Build configuration list for PBXNativeTarget "Readability-Objective-C ExampleTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C94035A819E9880300388A4B /* Debug */, + C94035A919E9880300388A4B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = C940357919E9880300388A4B /* Project object */; +} diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Base.lproj/Main.storyboard b/Readability-Objective-C Example/Readability-Objective-C Example/Base.lproj/Main.storyboard new file mode 100644 index 0000000..1877dfb --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Base.lproj/Main.storyboard @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.h b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.h new file mode 100644 index 0000000..b6db9e0 --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.h @@ -0,0 +1,15 @@ +// +// AppDelegate.h +// Readability-Objective-C Example +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import UIKit; + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.m b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.m new file mode 100644 index 0000000..1890267 --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/AppDelegate.m @@ -0,0 +1,17 @@ +// +// AppDelegate.m +// Readability-Objective-C Example +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +#import "AppDelegate.h" + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + return YES; +} + +@end diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.h b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.h new file mode 100644 index 0000000..cd24fb8 --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.h @@ -0,0 +1,13 @@ +// +// ViewController.h +// Readability-Objective-C Example +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import UIKit; + +@interface ViewController : UIViewController + +@end diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.m b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.m new file mode 100644 index 0000000..e546233 --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Classes/ViewController.m @@ -0,0 +1,72 @@ +// +// ViewController.m +// Readability-Objective-C Example +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +#import "ViewController.h" +#import "Readability.h" + +@interface ViewController () + +@property (nonatomic, weak) IBOutlet UIActivityIndicatorView *activityIndicator; +@property (nonatomic, weak) IBOutlet UITextView *textView; +@property (nonatomic, weak) IBOutlet UILabel *automatedReadabilityIndexLabel; +@property (nonatomic, weak) IBOutlet UILabel *colemanLiauIndexLabel; +@property (nonatomic, weak) IBOutlet UILabel *fleschReadingEaseLabel; +@property (nonatomic, weak) IBOutlet UILabel *fleschKincaidGradeLevelLabel; +@property (nonatomic, weak) IBOutlet UILabel *gunningFogScoreLabel; +@property (nonatomic, weak) IBOutlet UILabel *smogGradeLabel; + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self textViewDidChange:self.textView]; +} + +#pragma mark - UITextViewDelegate + +- (void)textViewDidChange:(UITextView *)textView { + if (textView.text.length) { + [self.activityIndicator startAnimating]; + + NSString *testText = self.textView.text; + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { + NSDecimalNumber *automatedReadabilityIndex = [Readability automatedReadabilityIndexForString:testText][@"Score"]; + NSDecimalNumber *colemanLiauIndex = [Readability colemanLiauIndexForString:testText]; + NSDecimalNumber *fleschKincaidGradeLevel = [Readability fleschKincaidGradeLevelForString:testText]; + NSDecimalNumber *fleschReadingEase = [Readability fleschReadingEaseForString:testText][@"Score"]; + NSDecimalNumber *gunningFogScore = [Readability gunningFogScoreForString:testText]; + NSDecimalNumber *smogGrade = [Readability smogGradeForString:testText]; + + dispatch_async(dispatch_get_main_queue(), ^(void) { + [self.activityIndicator stopAnimating]; + + [self.automatedReadabilityIndexLabel setText:[NSString stringWithFormat:@"%@", automatedReadabilityIndex]]; + [self.colemanLiauIndexLabel setText:[NSString stringWithFormat:@"%@", colemanLiauIndex]]; + [self.fleschKincaidGradeLevelLabel setText:[NSString stringWithFormat:@"%@", fleschKincaidGradeLevel]]; + [self.fleschReadingEaseLabel setText:[NSString stringWithFormat:@"%@", fleschReadingEase]]; + [self.gunningFogScoreLabel setText:[NSString stringWithFormat:@"%@", gunningFogScore]]; + [self.smogGradeLabel setText:[NSString stringWithFormat:@"%@", smogGrade]]; + }); + }); + } else { + [self.activityIndicator stopAnimating]; + + [self.automatedReadabilityIndexLabel setText:nil]; + [self.colemanLiauIndexLabel setText:nil]; + [self.fleschKincaidGradeLevelLabel setText:nil]; + [self.fleschReadingEaseLabel setText:nil]; + [self.gunningFogScoreLabel setText:nil]; + [self.smogGradeLabel setText:nil]; + } +} + +@end diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/AppIcon.appiconset/Contents.json b/Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..7006c9e --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,53 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/LaunchImage.launchimage/Contents.json b/Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000..b1fbfbc --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,9 @@ +{ + "images" : [ + + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/Info.plist b/Readability-Objective-C Example/Readability-Objective-C Example/Info.plist new file mode 100644 index 0000000..e92357d --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/Info.plist @@ -0,0 +1,36 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/Readability-Objective-C Example/Readability-Objective-C Example/main.m b/Readability-Objective-C Example/Readability-Objective-C Example/main.m new file mode 100644 index 0000000..2855871 --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C Example/main.m @@ -0,0 +1,17 @@ +// +// main.m +// Readability-Objective-C Example +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import UIKit; + +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/Readability-Objective-C Example/Readability-Objective-C ExampleTests/Info.plist b/Readability-Objective-C Example/Readability-Objective-C ExampleTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C ExampleTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Readability-Objective-C Example/Readability-Objective-C ExampleTests/Readability_Objective_C_ExampleTests.m b/Readability-Objective-C Example/Readability-Objective-C ExampleTests/Readability_Objective_C_ExampleTests.m new file mode 100644 index 0000000..b4dffcd --- /dev/null +++ b/Readability-Objective-C Example/Readability-Objective-C ExampleTests/Readability_Objective_C_ExampleTests.m @@ -0,0 +1,182 @@ +// +// Readability_Objective_C_ExampleTests.m +// Readability-Objective-C Example +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import CoreGraphics; +@import XCTest; + +#import "Readability.h" +#import "Readability+NSNumber.h" +#import "Readability+NSString.h" +#import "SyllableCounter.h" + +@interface Readability (Test) + +- (NSDecimalNumber *)roundFloat:(CGFloat)aFloat places:(NSInteger)places; +- (NSUInteger)wordsInString:(NSString *)string; +- (NSUInteger)sentencesInString:(NSString *)string; +- (NSUInteger)alphanumericCharactersInString:(NSString *)string; +- (NSString *)alphanumericString:(NSString *)string; +- (NSString *)cleanupWhiteSpace:(NSString *)string; +- (BOOL)isWordPolysyllable:(NSString *)word excludeCommonSuffixes:(BOOL)excludeCommonSuffixes; +- (NSUInteger)polysyllableWordsInString:(NSString *)string excludeCommonSuffixes:(BOOL)excludeCommonSuffixes; +- (BOOL)isWordCapitalized:(NSString *)word; +- (NSUInteger)complexWordsInString:(NSString *)string; + +@end + +@interface Readability_Objective_C_ExampleTests : XCTestCase + +@property (nonatomic, strong) NSString *testString1; +@property (nonatomic, strong) NSString *testString2; + +@end + +@implementation Readability_Objective_C_ExampleTests + +- (void)setUp { + [super setUp]; + + // read-able.com readability-score.com Readability-Objective-C + // Automated Readability Index: 9.7 9.7 9.7 + // Coleman–Liau Index: 15.0 15.0 14.9 + // Flesch Reading Ease: 24.4 30.9 24.4 + // Flesch–Kincaid Grade Level: 13.1 12.2 13.1 + // Gunning Fog Score: 14.4 11.4 14.4 + // SMOG Grade: 11.6 10.1 11.6 + self.testString1 = @"The Australian platypus is seemingly a hybrid of a mammal and reptilian creature."; + + // read-able.com readability-score.com Readability-Objective-C + // Automated Readability Index: 12.1 12.1 12.1 + // Coleman–Liau Index: 9.2 9.2 9.1 + // Flesch Reading Ease: 65.4 65.4 64.8 + // Flesch–Kincaid Grade Level: 10.9 10.9 11.0 + // Gunning Fog Score: 13.8 13.8 12.6 + // SMOG Grade: 8.3 8.3 8.3 + self.testString2 = @"Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth."; +} + +#pragma mark - Readability_iOS + +- (void)testReadabilityString1 { + NSDecimalNumber *automatedReadabilityIndex = [Readability automatedReadabilityIndexForString:self.testString1][@"Score"]; + NSDecimalNumber *fleschReadingEase = [Readability fleschReadingEaseForString:self.testString1][@"Score"]; + + XCTAssert(automatedReadabilityIndex.doubleValue == 9.7); + XCTAssert([Readability colemanLiauIndexForString:self.testString1].doubleValue == 14.9); + XCTAssert([Readability fleschKincaidGradeLevelForString:self.testString1].doubleValue == 13.1); + XCTAssert(fleschReadingEase.doubleValue == 24.4); + XCTAssert([Readability gunningFogScoreForString:self.testString1].doubleValue == 14.4); + XCTAssert([Readability smogGradeForString:self.testString1].doubleValue == 11.6); +} + +- (void)testReadabilityString2 { + NSDecimalNumber *automatedReadabilityIndexScore = [Readability automatedReadabilityIndexForString:self.testString2][@"Score"]; + NSString *automatedReadabilityIndexAges = [Readability automatedReadabilityIndexForString:self.testString2][@"Ages"]; + NSString *automatedReadabilityIndexUSASchoolLevel = [Readability automatedReadabilityIndexForString:self.testString2][@"USA School Level"]; + NSDecimalNumber *fleschReadingEaseScore = [Readability fleschReadingEaseForString:self.testString2][@"Score"]; + NSString *fleschReadingEaseUSASchoolLevel = [Readability fleschReadingEaseForString:self.testString2][@"USA School Level"]; + NSString *fleschReadingEaseNotes = [Readability fleschReadingEaseForString:self.testString2][@"Notes"]; + + XCTAssert(automatedReadabilityIndexScore.doubleValue == 12.1); + XCTAssert([automatedReadabilityIndexAges isEqualToString:@"16-17"]); + XCTAssert([automatedReadabilityIndexUSASchoolLevel isEqualToString:@"11"]); + XCTAssert([Readability colemanLiauIndexForString:self.testString2].doubleValue == 9.1); + XCTAssert([Readability fleschKincaidGradeLevelForString:self.testString2].doubleValue == 11.0); + XCTAssert(fleschReadingEaseScore.doubleValue == 64.8); + XCTAssert([fleschReadingEaseUSASchoolLevel isEqualToString:@"8-9"]); + XCTAssert([fleschReadingEaseNotes isEqualToString:@"Plain English. Easily understood by 13- to 15-year-old students."]); + XCTAssert([Readability gunningFogScoreForString:self.testString2].doubleValue == 12.6); + XCTAssert([Readability smogGradeForString:self.testString2].doubleValue == 8.3); +} + +- (void)testRoundFloat { + XCTAssert([[NSNumber numberWithFloat:9.7069229712853051f] roundToPlaces:1].floatValue == 9.7f); + XCTAssert([[NSNumber numberWithFloat:13.079999923706055f] roundToPlaces:2].floatValue == 13.08f); + XCTAssert([[NSNumber numberWithFloat:24.440014648437511f] roundToPlaces:3].floatValue == 24.440f); + XCTAssert([[NSNumber numberWithFloat:14.430769445804451f] roundToPlaces:4].floatValue == 14.4308f); + XCTAssert([[NSNumber numberWithFloat:11.573498725891113f] roundToPlaces:5].floatValue == 11.5735f); +} + +- (void)testWordCount { + XCTAssertEqual([self.testString1 wordCount], 13); + XCTAssertEqual([self.testString2 wordCount], 271); +} + +- (void)testSentenceCount { + XCTAssertEqual([self.testString1 sentenceCount], 1); + XCTAssertEqual([self.testString2 sentenceCount], 10); +} + +- (void)testAlphanumericCount { + XCTAssertEqual([self.testString1 alphanumericCount], 68); + XCTAssertEqual([self.testString2 alphanumericCount], 1149); +} + +- (void)testAlphanumeric { + XCTAssertEqual([self.testString1 alphanumeric].length, @"The Australian platypus is seemingly a hybrid of a mammal and reptilian creature".length); + XCTAssertEqual([self.testString2 alphanumeric].length, @"Four score and seven years ago our fathers brought forth on this continent a new nation conceived in liberty and dedicated to the proposition that all men are created equal Now we are engaged in a great civil war testing whether that nation or any nation so conceived and so dedicated can long endure We are met on a great battlefield of that war We have come to dedicate a portion of that field as a final resting place for those who here gave their lives that that nation might live It is altogether fitting and proper that we should do this But in a larger sense we can not dedicate we can not consecrate we can not hallow this ground The brave men living and dead who struggled here have consecrated it far above our poor power to add or detract The world will little note nor long remember what we say here but it can never forget what they did here It is for us the living rather to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced It is rather for us to be here dedicated to the great task remaining before us that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion that we here highly resolve that these dead shall not have died in vain that this nation under God shall have a new birth of freedom and that government of the people by the people for the people shall not perish from the earth".length); +} + +- (void)testCondense { + XCTAssertEqual([@" Test test test test " condense].length, @"Test test test test".length); +} + +- (void)testIsPolysyllableWithExcludingCommonSuffixes { + XCTAssert([@"crowdsourcing" isPolysyllableWithExcludingCommonSuffixes:NO] == YES); + XCTAssert([@"crowdsourcing" isPolysyllableWithExcludingCommonSuffixes:YES] == NO); +} + +- (void)testPolysyllableWordsWithExcludingCommonSuffixes { + XCTAssertEqual([self.testString1 polysyllableWordsWithExcludingCommonSuffixes:NO], 4); + XCTAssertEqual([self.testString1 polysyllableWordsWithExcludingCommonSuffixes:YES], 4); + + XCTAssertEqual([self.testString2 polysyllableWordsWithExcludingCommonSuffixes:NO], 20); + XCTAssertEqual([self.testString2 polysyllableWordsWithExcludingCommonSuffixes:YES], 12); +} + +- (void)testIsCapitalized { + XCTAssert([@"Test" isCapitalized] == YES); + XCTAssert([@"Test " isCapitalized] == YES); + XCTAssert([@"TEST" isCapitalized] == YES); + XCTAssert([@"A " isCapitalized] == YES); + XCTAssert([@"test" isCapitalized] == NO); + XCTAssert([@"tEst" isCapitalized] == NO); + XCTAssert([@" Test" isCapitalized] == NO); +} + +- (void)testComplexWordCount { + XCTAssertEqual([self.testString1 complexWordCount], 3); + XCTAssertEqual([self.testString2 complexWordCount], 12); +} + +#pragma mark - SyllableCounter + +- (void)testSyllableCountForWord { + XCTAssertEqual([SyllableCounter syllableCountForWord:@"The"], 1); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"Australian"], 4); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"platypus"], 3); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"is"], 1); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"seemingly"], 3); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"a"], 1); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"hybrid"], 2); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"of"], 1); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"mammal"], 2); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"and"], 1); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"reptilian"], 4); + XCTAssertEqual([SyllableCounter syllableCountForWord:@"creature."], 2); +} + +- (void)testSyllableCountForWords { + NSString *cleaned1 = [self.testString1 alphanumeric]; + NSString *cleaned2 = [self.testString2 alphanumeric]; + + XCTAssertEqual([SyllableCounter syllableCountForWords:cleaned1], 26); + XCTAssertEqual([SyllableCounter syllableCountForWords:cleaned2], 367); +} + +@end diff --git a/Readability/Readability+NSNumber.h b/Readability/Readability+NSNumber.h new file mode 100644 index 0000000..9405fc8 --- /dev/null +++ b/Readability/Readability+NSNumber.h @@ -0,0 +1,15 @@ +// +// Readability+NSNumber.h +// Readability-Objective-C +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import Foundation; + +@interface NSNumber (Readability) + +- (NSDecimalNumber *)roundToPlaces:(NSInteger)places; + +@end diff --git a/Readability/Readability+NSNumber.m b/Readability/Readability+NSNumber.m new file mode 100644 index 0000000..1c1410d --- /dev/null +++ b/Readability/Readability+NSNumber.m @@ -0,0 +1,25 @@ +// +// Readability+NSNumber.m +// Readability-Objective-C +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +#import "Readability+NSNumber.h" + +@implementation NSNumber (Readability) + +- (NSDecimalNumber *)roundToPlaces:(NSInteger)places { + NSDecimalNumber *decimalNumber = [[NSDecimalNumber alloc] initWithFloat:self.floatValue]; + NSDecimalNumberHandler *decimalNumberHandler = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain + scale:places + raiseOnExactness:NO + raiseOnOverflow:NO + raiseOnUnderflow:NO + raiseOnDivideByZero:NO]; + + return [decimalNumber decimalNumberByRoundingAccordingToBehavior:decimalNumberHandler]; +} + +@end diff --git a/Readability/Readability+NSString.h b/Readability/Readability+NSString.h new file mode 100644 index 0000000..c7863f8 --- /dev/null +++ b/Readability/Readability+NSString.h @@ -0,0 +1,24 @@ +// +// Readability+NSString.h +// Readability-Objective-C +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import Foundation; + +@interface NSString (Readability) + +- (BOOL)isPolysyllableWithExcludingCommonSuffixes:(BOOL)excludeCommonSuffixes; +- (NSUInteger)polysyllableWordsWithExcludingCommonSuffixes:(BOOL)excludeCommonSuffixes; +- (NSUInteger)complexWordCount; +- (BOOL)isCapitalized; +- (BOOL)isAlphanumeric; +- (NSString *)alphanumeric; +- (NSUInteger)alphanumericCount; +- (NSString *)condense; +- (NSUInteger)sentenceCount; +- (NSUInteger)wordCount; + +@end diff --git a/Readability/Readability+NSString.m b/Readability/Readability+NSString.m new file mode 100644 index 0000000..45c4c5f --- /dev/null +++ b/Readability/Readability+NSString.m @@ -0,0 +1,132 @@ +// +// Readability+NSString.m +// Readability-Objective-C +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +#import "Readability+NSString.h" +#import "SyllableCounter.h" + +@implementation NSString (Readability) + +- (BOOL)isPolysyllableWithExcludingCommonSuffixes:(BOOL)excludeCommonSuffixes { + __block BOOL polysyllable = NO; + + if ([SyllableCounter syllableCountForWord:self] > 2) { + if (excludeCommonSuffixes) { + if (![self.lowercaseString hasSuffix:@"es"] && + ![self.lowercaseString hasSuffix:@"ed"] && + ![self.lowercaseString hasSuffix:@"ing"]) { + polysyllable = YES; + } + } else { + polysyllable = YES; + } + } + + return polysyllable; +} + +- (NSUInteger)polysyllableWordsWithExcludingCommonSuffixes:(BOOL)excludeCommonSuffixes { + __block NSUInteger count = 0; + + [self enumerateSubstringsInRange:NSMakeRange(0, self.length) + options:NSStringEnumerationByWords + usingBlock:^(NSString *word, NSRange wordRange, NSRange enclosingRange, BOOL *stop) { + if ([word isPolysyllableWithExcludingCommonSuffixes:excludeCommonSuffixes]) { + count++; + } + }]; + + return count; +} + +- (NSUInteger)complexWordCount { + __block NSUInteger count = 0; + + [self enumerateSubstringsInRange:NSMakeRange(0, self.length) + options:NSStringEnumerationByWords + usingBlock:^(NSString *word, NSRange wordRange, NSRange enclosingRange, BOOL *stop) { + // Attemping the complex word suggestions at http://en.wikipedia.org/wiki/Gunning_fog_index + BOOL polysyllable = [word isPolysyllableWithExcludingCommonSuffixes:YES]; + BOOL properNoun = [word isCapitalized]; + BOOL familiarJargon = NO; // TODO: Implement + BOOL compound = NO; // TODO: Implement + + if (polysyllable && !properNoun && !familiarJargon && !compound) { + count++; + } + }]; + + return count; +} + +- (BOOL)isCapitalized { + unichar character = [self characterAtIndex:0]; + BOOL capitalized = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:character]; + + return capitalized; +} + +- (BOOL)isAlphanumeric { + if ([self alphanumeric].length > 0) { + return YES; + } + + return NO; +} + +- (NSString *)alphanumeric { + NSCharacterSet *charactersToRemove = [NSCharacterSet alphanumericCharacterSet].invertedSet; + NSArray *componentsSeparated = [self componentsSeparatedByCharactersInSet:charactersToRemove]; + NSString *componentsJoined = [componentsSeparated componentsJoinedByString:@" "]; + + return [componentsJoined condense]; +} + +- (NSUInteger)alphanumericCount { + NSCharacterSet *charactersToRemove = [NSCharacterSet alphanumericCharacterSet].invertedSet; + NSArray *componentsSeparated = [self componentsSeparatedByCharactersInSet:charactersToRemove]; + NSUInteger count = 0; + + for (NSString *word in componentsSeparated) { + if (word.length > 0) { + count += word.length; + } + } + + return count; +} + +- (NSString *)condense { + NSString *squashed = [self stringByReplacingOccurrencesOfString:@"[ ]+" + withString:@" " + options:NSRegularExpressionSearch + range:NSMakeRange(0, self.length)]; + + return [squashed stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; +} + +- (NSUInteger)count:(NSStringEnumerationOptions)option { + __block NSUInteger count = 0; + + [self enumerateSubstringsInRange:NSMakeRange(0, self.length) + options:option + usingBlock:^(NSString *word, NSRange wordRange, NSRange enclosingRange, BOOL *stop) { + count++; + }]; + + return count; +} + +- (NSUInteger)sentenceCount { + return [self count:NSStringEnumerationBySentences]; +} + +- (NSUInteger)wordCount { + return [self count:NSStringEnumerationByWords]; +} + +@end diff --git a/Readability/Readability.h b/Readability/Readability.h new file mode 100644 index 0000000..4eda790 --- /dev/null +++ b/Readability/Readability.h @@ -0,0 +1,27 @@ +// +// Readability.h +// Readability-Objective-C +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +// Automated Readability Index: automatedReadabilityIndexForString +// Coleman–Liau Index: colemanLiauIndexForString +// Flesch-Kincaid Grade Level: fleschKincaidGradeLevelForString +// Flesch Reading Ease: fleschReadingEaseForString +// Gunning Fog Index: gunningFogScoreForString +// SMOG Grade: smogGradeForString + +@import Foundation; + +@interface Readability : NSObject + ++ (NSDictionary *)automatedReadabilityIndexForString:(NSString *)string; ++ (NSDecimalNumber *)colemanLiauIndexForString:(NSString *)string; ++ (NSDecimalNumber *)fleschKincaidGradeLevelForString:(NSString *)string; ++ (NSDictionary *)fleschReadingEaseForString:(NSString *)string; ++ (NSDecimalNumber *)gunningFogScoreForString:(NSString *)string; ++ (NSDecimalNumber *)smogGradeForString:(NSString *)string; + +@end diff --git a/Readability/Readability.m b/Readability/Readability.m new file mode 100644 index 0000000..d6ed68f --- /dev/null +++ b/Readability/Readability.m @@ -0,0 +1,211 @@ +// +// Readability.m +// Readability-Objective-C +// +// Created by brackendev. +// Copyright (c) 2014-2019 brackendev. All rights reserved. +// + +@import CoreGraphics; + +#import "Readability.h" +#import "Readability+NSNumber.h" +#import "Readability+NSString.h" +#import "SyllableCounter.h" + +@implementation Readability + +#pragma mark - Automated Readability Index +// http://en.wikipedia.org/wiki/Automated_Readability_Index + ++ (NSDictionary *)automatedReadabilityIndexForString:(NSString *)string { + NSDecimalNumber *score = [self automatedReadabilityIndexScoreForString:string]; + NSDictionary *dict = @{@"Score": score, + @"Ages": [self automatedReadabilityIndexAgesForScore:score.floatValue], + @"USA School Level": [self automatedReadabilityIndexUSASchoolLevelForScore:score.floatValue]}; + + return dict; +} + ++ (NSDecimalNumber *)automatedReadabilityIndexScoreForString:(NSString *)string { + CGFloat totalWords = (CGFloat)[string wordCount]; + CGFloat totalSentences = (CGFloat)[string sentenceCount]; + CGFloat totalAlphanumericCharacters = (CGFloat)[string alphanumericCount]; + CGFloat score = 4.71f * (totalAlphanumericCharacters / totalWords) + 0.5f * (totalWords / totalSentences) - 21.43f; + + return [[NSNumber numberWithFloat:score] roundToPlaces:1]; +} + ++ (NSString *)automatedReadabilityIndexAgesForScore:(CGFloat)score { + if (score >= 15) { + return @"23+"; + } else if (score >= 14) { + return @"18-22"; + } else if (score >= 13) { + return @"17-18"; + } else if (score >= 12) { + return @"16-17"; + } else if (score >= 11) { + return @"15-16"; + } else if (score >= 10) { + return @"14-15"; + } else if (score >= 9) { + return @"13-14"; + } else if (score >= 8) { + return @"12-13"; + } else if (score >= 7) { + return @"11-12"; + } else if (score >= 6) { + return @"10-11"; + } else if (score >= 5) { + return @"9-10"; + } else if (score >= 4) { + return @"8-9"; + } else if (score >= 3) { + return @"7-8"; + } else if (score >= 2) { + return @"6-7"; + } else { + return @"5-6"; + } +} + ++ (NSString *)automatedReadabilityIndexUSASchoolLevelForScore:(CGFloat)score { + if (score >= 14) { + return @"College"; + } else if (score >= 13) { + return @"12"; + } else if (score >= 12) { + return @"11"; + } else if (score >= 11) { + return @"10"; + } else if (score >= 10) { + return @"9"; + } else if (score >= 9) { + return @"8"; + } else if (score >= 8) { + return @"7"; + } else if (score >= 7) { + return @"6"; + } else if (score >= 6) { + return @"5"; + } else if (score >= 5) { + return @"4"; + } else if (score >= 4) { + return @"3"; + } else if (score >= 3) { + return @"2"; + } else if (score >= 2) { + return @"1"; + } else { + return @"Kindergarten"; + } +} + +#pragma mark - Coleman-Liau Index +// http://en.wikipedia.org/wiki/Coleman–Liau_index + ++ (NSDecimalNumber *)colemanLiauIndexForString:(NSString *)string { + CGFloat totalWords = [string wordCount]; + CGFloat totalSentences = [string sentenceCount]; + CGFloat totalAlphanumericCharacters = [string alphanumericCount]; + CGFloat score = 5.88f * (totalAlphanumericCharacters / totalWords) - 0.296f * (totalSentences / totalWords) - 15.8f; + + return [[NSNumber numberWithFloat:score] roundToPlaces:1]; +} + +#pragma mark - Flesch-Kincaid Grade Level +// http://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests + ++ (NSDecimalNumber *)fleschKincaidGradeLevelForString:(NSString *)string { + CGFloat totalWords = [string wordCount]; + CGFloat totalSentences = [string sentenceCount]; + NSString *alphaNumeric = [string alphanumeric]; + CGFloat totalSyllables = [SyllableCounter syllableCountForWords:alphaNumeric]; + CGFloat score = 0.39f * (totalWords / totalSentences) + 11.8f * (totalSyllables / totalWords) - 15.59f; + + return [[NSNumber numberWithFloat:score] roundToPlaces:1]; +} + +#pragma mark - Flesch Reading Ease +// http://en.wikipedia.org/wiki/Flesch–Kincaid_readability_tests + ++ (NSDictionary *)fleschReadingEaseForString:(NSString *)string { + NSDecimalNumber *score = [self fleschReadingEaseScoreForString:string]; + NSDictionary *dict = @{@"Score": score, + @"USA School Level": [self fleschReadingEaseUSASchoolLevelForScore:score.floatValue], + @"Notes": [self fleschReadingEaseNotesForScore:score.floatValue]}; + + return dict; +} + ++ (NSDecimalNumber *)fleschReadingEaseScoreForString:(NSString *)string { + CGFloat totalWords = [string wordCount]; + CGFloat totalSentences = [string sentenceCount]; + NSString *alphaNumeric = [string alphanumeric]; + CGFloat totalSyllables = [SyllableCounter syllableCountForWords:alphaNumeric]; + CGFloat score = 206.835f - (1.015f * (totalWords / totalSentences)) - (84.6f * (totalSyllables / totalWords)); + + return [[NSNumber numberWithFloat:score] roundToPlaces:1]; +} + ++ (NSString *)fleschReadingEaseUSASchoolLevelForScore:(CGFloat)score { + if (score >= 90) { + return @"5"; + } else if (score >= 80) { + return @"6"; + } else if (score >= 70) { + return @"7"; + } else if (score >= 60) { + return @"8-9"; + } else if (score >= 50) { + return @"10-12"; + } else if (score >= 30) { + return @"College"; + } else { + return @"College Graduate"; + } +} + ++ (NSString *)fleschReadingEaseNotesForScore:(CGFloat)score { + if (score >= 90) { + return @"Very easy to read. Easily understood by an average 11-year-old student."; + } else if (score >= 80) { + return @"Easy to read. Conversational English for consumers."; + } else if (score >= 70) { + return @"Fairly easy to read."; + } else if (score >= 60) { + return @"Plain English. Easily understood by 13- to 15-year-old students."; + } else if (score >= 50) { + return @"Fairly difficult to read."; + } else if (score >= 30) { + return @"Difficult to read."; + } else { + return @"Very difficult to read. Best understood by university graduates."; + } +} + +#pragma mark - Gunning Fog Score +// http://en.wikipedia.org/wiki/Gunning_fog_index + ++ (NSDecimalNumber *)gunningFogScoreForString:(NSString *)string { + CGFloat totalWords = [string wordCount]; + CGFloat totalSentences = [string sentenceCount]; + CGFloat totalComplexWords = [string complexWordCount]; + CGFloat score = 0.4f * ((totalWords / totalSentences) + 100.0f * (totalComplexWords / totalWords)); + + return [[NSNumber numberWithFloat:score] roundToPlaces:1]; +} + +#pragma mark - SMOG Grade +// http://en.wikipedia.org/wiki/Gunning_fog_index + ++ (NSDecimalNumber *)smogGradeForString:(NSString *)string { + CGFloat totalSentences = [string sentenceCount]; + CGFloat totalPolysyllables = [string polysyllableWordsWithExcludingCommonSuffixes:NO]; + CGFloat score = 1.043f * sqrtf(totalPolysyllables * (30.0f / totalSentences) + 3.1291f); + + return [[NSNumber numberWithFloat:score] roundToPlaces:1]; +} + +@end diff --git a/Readability/objC-syllable-counter b/Readability/objC-syllable-counter new file mode 160000 index 0000000..cb4d52d --- /dev/null +++ b/Readability/objC-syllable-counter @@ -0,0 +1 @@ +Subproject commit cb4d52d8875feea729ec6a82b64d3065e58b82e3 diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..277f1f2 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman