-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
587 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ targets: | |
options: | ||
explicit_to_json: true | ||
include_if_null: false | ||
nullable: true | ||
nullable: true | ||
any_map: true |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import 'dart:collection'; | ||
import 'package:oxford_dictionary/oxford_dict.dart' as remote; | ||
import 'package:oxford_dictionary/src/entries/model/cross_reference.dart'; | ||
import 'package:oxford_dictionary/src/entries/model/grammatical_feature.dart'; | ||
|
||
class Word { | ||
final String id; | ||
final String word; | ||
final String language; | ||
final Map<remote.LexicalCategory, List<Variant>> variants; | ||
final Map<remote.LexicalCategory, List<String>> phrases; | ||
final remote.DictionaryEntries rawResponse; | ||
|
||
Word.fromEntry(remote.DictionaryEntries entry) | ||
: id = entry.id, | ||
word = entry.word, | ||
language = entry.results?.first?.language, | ||
variants = SplayTreeMap.of( | ||
Map.fromEntries( | ||
entry.results | ||
.map( | ||
(e) => e.lexicalEntries.map( | ||
(e) => MapEntry( | ||
e.lexicalCategory, | ||
e.entries | ||
.map( | ||
(e) => Variant.fromLexicalEntry(e), | ||
) | ||
.toList(), | ||
), | ||
), | ||
) | ||
.expand((element) => element) | ||
.fold<List<MapEntry<remote.LexicalCategory, List<Variant>>>>( | ||
[], | ||
(reduced, element) { | ||
if (reduced.map((e) => e.key).contains(element.key)) { | ||
final list = reduced.firstWhere((reducedElement) => reducedElement.key == element.key).value; | ||
list.addAll([...element.value]); | ||
list.sort( | ||
(e1, e2) => e1.grammaticalFeatures == null ? -1 : 1, | ||
); | ||
} else { | ||
reduced.add(MapEntry(element.key, element.value)); | ||
} | ||
return reduced; | ||
}, | ||
), | ||
), | ||
(k1, k2) => k1.compareTo(k2), | ||
), | ||
phrases = Map.fromEntries( | ||
entry.results | ||
?.where((element) => element != null) | ||
?.map( | ||
(e) => e.lexicalEntries?.where((element) => element != null)?.map( | ||
(e) => MapEntry( | ||
e.lexicalCategory, | ||
e.phrases?.where((element) => element != null)?.map((e) => e.text)?.toList(), | ||
), | ||
), | ||
) | ||
?.expand((element) => element), | ||
), | ||
rawResponse = entry; | ||
|
||
} | ||
|
||
class Variant { | ||
final List<String> etymologies; | ||
final String homographNumber; | ||
final List<GrammaticalFeature> grammaticalFeatures; | ||
final List<remote.Pronunciation> pronunciations; | ||
final List<Sense> senses; | ||
|
||
Variant.fromLexicalEntry(remote.LexicalEntry entry) | ||
: senses = entry.senses.map((e) => Sense.fromRemoteSense(e)).toList(), | ||
grammaticalFeatures = entry.grammaticalFeatures, | ||
homographNumber = entry.homographNumber, | ||
pronunciations = entry.pronunciations, | ||
etymologies = entry.etymologies; | ||
|
||
} | ||
|
||
class Sense { | ||
final List<String> definitions; | ||
final List<CrossReference> crossReferences; | ||
final List<String> shortDefinitions; | ||
final List<String> examples; | ||
final List<String> synonyms; | ||
final List<String> semanticClasses; | ||
final List<String> domains; | ||
final List<Sense> subSenses; | ||
final List<String> constructions; | ||
final bool isCrossReferenced; | ||
|
||
Sense.fromRemoteSense(remote.SenseFromRemote remoteSense) | ||
: definitions = remoteSense.definitions ?? remoteSense.crossReferenceMarkers, | ||
crossReferences = remoteSense.crossReferences, | ||
subSenses = remoteSense.subSenses?.map((e) => Sense.fromRemoteSense(e))?.toList(), | ||
constructions = remoteSense.constructions?.map((e) => e.text)?.toList(), | ||
synonyms = remoteSense.synonyms?.map((e) => e.text)?.toList(), | ||
isCrossReferenced = remoteSense.crossReferenceMarkers != null && remoteSense.definitions == null, | ||
shortDefinitions = remoteSense.shortDefinitions, | ||
examples = remoteSense.examples?.map((e) => e.text)?.toList(), | ||
semanticClasses = remoteSense.semanticClasses?.map((e) => e.text)?.toList(), | ||
domains = remoteSense.domainClasses?.map((e) => e.text)?.toList(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'cross_reference.g.dart'; | ||
|
||
@JsonSerializable() | ||
class CrossReference { | ||
final String id; | ||
final String text; | ||
final String type; | ||
|
||
CrossReference(this.id, this.text, this.type); | ||
|
||
factory CrossReference.fromJson(Map json) => _$CrossReferenceFromJson(json); | ||
|
||
Map toJson() => _$CrossReferenceToJson(this); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'grammatical_feature.g.dart'; | ||
|
||
@JsonSerializable() | ||
class GrammaticalFeature { | ||
final String id; | ||
final String text; | ||
final String type; | ||
|
||
GrammaticalFeature(this.id, this.text, this.type); | ||
|
||
factory GrammaticalFeature.fromJson(Map json) => _$GrammaticalFeatureFromJson(json); | ||
|
||
Map toJson() => _$GrammaticalFeatureToJson(this); | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:oxford_dictionary/src/entries/model/cross_reference.dart'; | ||
|
||
import 'grammatical_feature.dart'; | ||
import 'pronunciation.dart'; | ||
import 'sense.dart'; | ||
|
||
part 'lexical_entry.g.dart'; | ||
|
||
@JsonSerializable() | ||
class LexicalEntry { | ||
final List<String> crossReferenceMarkers; | ||
final List<CrossReference> crossReferences; | ||
final List<GrammaticalFeature> grammaticalFeatures; | ||
final List<String> etymologies; | ||
final String homographNumber; | ||
final List<Pronunciation> pronunciations; | ||
final List<Sense> senses; | ||
final List<SenseFromRemote> senses; | ||
|
||
LexicalEntry({this.etymologies, this.homographNumber, this.pronunciations, this.senses}); | ||
LexicalEntry({ | ||
this.grammaticalFeatures, | ||
this.crossReferenceMarkers, | ||
this.crossReferences, | ||
this.etymologies, | ||
this.homographNumber, | ||
this.pronunciations, | ||
this.senses, | ||
}); | ||
|
||
factory LexicalEntry.fromJson(Map<String, dynamic> json) => _$EntryFromJson(json); | ||
factory LexicalEntry.fromJson(Map<String, dynamic> json) => _$LexicalEntryFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$EntryToJson(this); | ||
Map<String, dynamic> toJson() => _$LexicalEntryToJson(this); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,53 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:oxford_dictionary/src/entries/model/synonim.dart'; | ||
|
||
import 'cross_reference.dart'; | ||
import 'domain_class.dart'; | ||
import 'example.dart'; | ||
import 'semantic_classes.dart'; | ||
|
||
part 'sense.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Sense { | ||
class Construction { | ||
final String text; | ||
|
||
Construction(this.text); | ||
|
||
factory Construction.fromJson(Map json) => _$ConstructionFromJson(json); | ||
|
||
Map toJson() => _$ConstructionToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class SenseFromRemote { | ||
final List<Construction> constructions; | ||
final List<String> definitions; | ||
final List<DomainClass> domainClasses; | ||
final List<Example> examples; | ||
final List<Synonym> synonyms; | ||
final String id; | ||
final List<SemanticClass> semanticClasses; | ||
final List<String> shortDefinitions; | ||
final List<String> crossReferenceMarkers; | ||
final List<CrossReference> crossReferences; | ||
@JsonKey(name: 'subsenses') | ||
final List<SenseFromRemote> subSenses; | ||
|
||
Sense(this.definitions, this.domainClasses, this.examples, this.id, this.semanticClasses, this.shortDefinitions); | ||
SenseFromRemote( | ||
this.definitions, | ||
this.domainClasses, | ||
this.examples, | ||
this.id, | ||
this.semanticClasses, | ||
this.shortDefinitions, | ||
this.crossReferenceMarkers, | ||
this.crossReferences, | ||
this.subSenses, | ||
this.constructions, this.synonyms, | ||
); | ||
|
||
factory Sense.fromJson(Map<String, dynamic> json) => _$SenseFromJson(json); | ||
factory SenseFromRemote.fromJson(Map json) => _$SenseFromRemoteFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$SenseToJson(this); | ||
Map toJson() => _$SenseFromRemoteToJson(this); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'synonim.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Synonym { | ||
final String language; | ||
final String text; | ||
|
||
Synonym(this.language, this.text); | ||
|
||
factory Synonym.fromJson(Map json) => _$SynonymFromJson(json); | ||
|
||
Map toJson() => _$SynonymToJson(this); | ||
} |
Oops, something went wrong.