Skip to content

Instantly share code, notes, and snippets.

@Sajjon
Created August 15, 2020 14:39
Show Gist options
  • Save Sajjon/6326dca86ee196a108903e10c673e804 to your computer and use it in GitHub Desktop.
Save Sajjon/6326dca86ee196a108903e10c673e804 to your computer and use it in GitHub Desktop.
LineFromCorpusFromLine
protocol LineFromCorpusConvertible: CustomStringConvertible, Codable {
/// The word, on lowercased form
var wordForm: WordForm { get }
/// Part of speech tag, only first major tag, .e.g from line `han PN.UTR.SIN.DEF.SUB`, we only save `PN`
var partOfSpeechTag: PartOfSpeech { get }
/// Base form(s) of word
var lemgrams: Lemgrams { get }
/// Whether this is a compound word or not, an example of a compound word is 🇸🇪_"stämband"_,
/// consisting of the word _"stäm"_ and the word _"band"_.
var isCompoundWord: Bool { get }
/// The total frequency, the number of occurences of the word form in the corpus.
var numberOfOccurencesInCorpus: Int { get }
/// The relative frequency of the word form in the corpus per 1 million words.
var relativeFrequencyPerOneMillion: Int { get }
// MARK: Meta properties
/// The index of this parsed line in the corpus
var indexOfLineInCorpus: Int { get }
}
protocol LineFromCorpusConvertibleByProxy: LineFromCorpusConvertible {
associatedtype FromLine: LineFromCorpusConvertible
var line: FromLine { get }
}
extension LineFromCorpusConvertibleByProxy {
var wordForm: WordForm { line.wordForm }
var partOfSpeechTag: PartOfSpeech { line.partOfSpeechTag }
var lemgrams: Lemgrams { line.lemgrams }
var isCompoundWord: Bool { line.isCompoundWord }
var numberOfOccurencesInCorpus: Int { line.numberOfOccurencesInCorpus }
var relativeFrequencyPerOneMillion: Int { line.relativeFrequencyPerOneMillion }
var indexOfLineInCorpus: Int { line.indexOfLineInCorpus }
}
protocol LineFromCorpusFromLineAndOther: LineFromCorpusConvertibleByProxy {
associatedtype Other
init(line: FromLine, other: Other)
}
protocol LineFromCorpusFromLine: LineFromCorpusFromLineAndOther where Other == Void {
init(line: FromLine)
}
extension LineFromCorpusFromLine {
init(line: FromLine, other: Void) {
self.init(line: line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment