This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import NaturalLanguage | |
| let text = "Elinde güzel bir çiçek vardı." | |
| let tagger = NLTagger(tagSchemes: [.lexicalClass]) | |
| tagger.string = text | |
| let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace] | |
| tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .lexicalClass, options: options) { tag, tokenRange in | |
| if let tag = tag { | |
| print("\(text[tokenRange]): \(tag.rawValue)") | |
| } | |
| return true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import NaturalLanguage | |
| let text = "The American Red Cross was established in Washington, D.C., by Clara Barton." | |
| let tagger = NLTagger(tagSchemes: [.nameType]) | |
| tagger.string = text | |
| let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace, .joinNames] | |
| let tags: [NLTag] = [.personalName, .placeName, .organizationName] | |
| tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .nameType, options: options) { tag, tokenRange in | |
| if let tag = tag, tags.contains(tag) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import CreateML | |
| import Foundation | |
| // Read from CSV | |
| var data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ozgur/dataset/fortnite.csv")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let parsingOptions = MLDataTable.ParsingOptions(containsHeader: true, delimiter: ",", comment: "", escape: "", doubleQuote: false, quote: "", skipInitialSpaces: false, missingValues: [], lineTerminator: "\r", selectColumns:["author","rating","review"], maxRows: nil, skipRows: 0) | |
| var table = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ozgur/Downloads/fortnite.csv"), options: parsingOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import CreateML | |
| // Read from CSV | |
| var data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ozgur/Documents/CreateMLFiles/englishwords.csv")) | |
| let newColumn = data.map { row -> String in | |
| guard | |
| let score1 = row["score1"]?.doubleValue, | |
| let score2 = row["score2"]?.doubleValue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// - Tag: CheckSceneStability | |
| fileprivate func sceneStabilityAchieved() -> Bool { | |
| // Determine if we have enough evidence of stability. | |
| if transpositionHistoryPoints.count == maximumHistoryLength { | |
| // Calculate the moving average. | |
| var movingAverage: CGPoint = CGPoint.zero | |
| for currentPoint in transpositionHistoryPoints { | |
| movingAverage.x += currentPoint.x | |
| movingAverage.y += currentPoint.y | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
| guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { | |
| return | |
| } | |
| guard previousPixelBuffer != nil else { | |
| previousPixelBuffer = pixelBuffer | |
| self.resetTranspositionHistory() | |
| return | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| See LICENSE folder for this sample’s licensing information. | |
| Abstract: | |
| Implements the Vision view controller. | |
| */ | |
| import UIKit | |
| import AVFoundation | |
| import Vision |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if self.sceneStabilityAchieved() { | |
| showDetectionOverlay(true) | |
| if currentlyAnalyzedPixelBuffer == nil { | |
| // Retain the image buffer for Vision processing. | |
| currentlyAnalyzedPixelBuffer = pixelBuffer | |
| analyzeCurrentImage() | |
| } | |
| } else { | |
| showDetectionOverlay(false) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if let results = registrationRequest.results { | |
| if let alignmentObservation = results.first as? VNImageTranslationAlignmentObservation { | |
| let alignmentTransform = alignmentObservation.alignmentTransform | |
| self.recordTransposition(CGPoint(x: alignmentTransform.tx, y: alignmentTransform.ty)) | |
| } | |
| } |