FormulaElement as abstract class
This commit is contained in:
parent
f70d744ef7
commit
6133e58226
5 changed files with 19 additions and 13 deletions
3
TODO.md
3
TODO.md
|
|
@ -17,7 +17,8 @@
|
||||||
- Drift files have a lot of duplicate code. "web" version is the same as native version, only _openConnection is diferrent. Refactor to not duplicate code.
|
- Drift files have a lot of duplicate code. "web" version is the same as native version, only _openConnection is diferrent. Refactor to not duplicate code.
|
||||||
- [X] Create Formula.toStringLiteral. It is the reverse of Formula.fromSet( Formula.fromArrayStringLiteral(string)[0] )
|
- [X] Create Formula.toStringLiteral. It is the reverse of Formula.fromSet( Formula.fromArrayStringLiteral(string)[0] )
|
||||||
- [X] Create UnitSpec.toStringLiteral, like Formula.toStringLiteral
|
- [X] Create UnitSpec.toStringLiteral, like Formula.toStringLiteral
|
||||||
- [ ] Make Formula and UnitSpec subclasses of FormulaElement. Change return type of functions that return Object to FormulaElement if necessary.
|
- [X] Make Formula and UnitSpec subclasses of FormulaElement. Change return type of functions that return Object to FormulaElement if necessary.
|
||||||
|
- [ ] Define toStringLiteral in FormulaElement.
|
||||||
- Database file location:
|
- Database file location:
|
||||||
- [ ] In linux, the sqlite database file will be located following rules at https://specifications.freedesktop.org/basedir/latest/
|
- [ ] In linux, the sqlite database file will be located following rules at https://specifications.freedesktop.org/basedir/latest/
|
||||||
- [ ] In Windows, the sqlite database file will be in %appdata%/Roaming
|
- [ ] In Windows, the sqlite database file will be in %appdata%/Roaming
|
||||||
|
|
|
||||||
2
flutterw
2
flutterw
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
set -x
|
#set -x
|
||||||
|
|
||||||
BUILDCACHE=./.build-container-cache
|
BUILDCACHE=./.build-container-cache
|
||||||
DOCKERFILE=./docker/Dockerfile
|
DOCKERFILE=./docker/Dockerfile
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:d4rt/d4rt.dart';
|
import 'package:d4rt/d4rt.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:d4rt_formulas/d4rt_formulas.dart';
|
import 'package:d4rt_formulas/d4rt_formulas.dart';
|
||||||
|
import 'formula_models.dart';
|
||||||
|
|
||||||
class Multimap<K, V> extends DelegatingMap<K, List<V>> {
|
class Multimap<K, V> extends DelegatingMap<K, List<V>> {
|
||||||
final Map<K, List<V>> _map;
|
final Map<K, List<V>> _map;
|
||||||
|
|
@ -182,7 +183,7 @@ class Corpus{
|
||||||
|
|
||||||
/// Loads formula elements, making sure to load units first, then formulas
|
/// Loads formula elements, making sure to load units first, then formulas
|
||||||
/// to avoid dependency issues.
|
/// to avoid dependency issues.
|
||||||
void loadFormulaElements(List<Object> elements) {
|
void loadFormulaElements(List<FormulaElement> elements) {
|
||||||
List<UnitSpec> units = [];
|
List<UnitSpec> units = [];
|
||||||
List<Formula> formulas = [];
|
List<Formula> formulas = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ Future<Corpus> createDefaultCorpus() async{
|
||||||
print( "Loading units from $unitRes");
|
print( "Loading units from $unitRes");
|
||||||
final literal = await loadResourceAsString(unitRes);
|
final literal = await loadResourceAsString(unitRes);
|
||||||
final units = UnitSpec.fromArrayStringLiteral(literal);
|
final units = UnitSpec.fromArrayStringLiteral(literal);
|
||||||
corpus.loadFormulaElements(units);
|
final formulaElements = units.cast<FormulaElement>();
|
||||||
|
corpus.loadFormulaElements(formulaElements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +50,8 @@ Future<Corpus> createDefaultCorpus() async{
|
||||||
for (final formRes in formulaResources) {
|
for (final formRes in formulaResources) {
|
||||||
final literal = await loadResourceAsString(formRes);
|
final literal = await loadResourceAsString(formRes);
|
||||||
final formulas = Formula.fromArrayStringLiteral(literal);
|
final formulas = Formula.fromArrayStringLiteral(literal);
|
||||||
corpus.loadFormulaElements(formulas);
|
final formulaElements = formulas.cast<FormulaElement>();
|
||||||
|
corpus.loadFormulaElements(formulaElements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ List<Object?> parseD4rtLiteral(String arrayStringLiteral) {
|
||||||
|
|
||||||
/// Parses corpus elements from an array string literal.
|
/// Parses corpus elements from an array string literal.
|
||||||
/// Determines if each element is a formula or a unit and converts accordingly.
|
/// Determines if each element is a formula or a unit and converts accordingly.
|
||||||
List<Object> parseCorpusElements(String arrayStringLiteral) {
|
List<FormulaElement> parseCorpusElements(String arrayStringLiteral) {
|
||||||
final List<Object?> elements = parseD4rtLiteral(arrayStringLiteral);
|
final List<Object?> elements = parseD4rtLiteral(arrayStringLiteral);
|
||||||
|
|
||||||
final List<Object> result = [];
|
final List<FormulaElement> result = [];
|
||||||
for (final element in elements) {
|
for (final element in elements) {
|
||||||
if (element is Map<Object?, Object?>) {
|
if (element is Map<Object?, Object?>) {
|
||||||
// Check if it's a formula by looking for required formula properties
|
// Check if it's a formula by looking for required formula properties
|
||||||
|
|
@ -66,8 +66,10 @@ List<Object> parseCorpusElements(String arrayStringLiteral) {
|
||||||
|
|
||||||
typedef Number = double;
|
typedef Number = double;
|
||||||
|
|
||||||
|
/// Abstract base class for formula elements
|
||||||
|
abstract class FormulaElement {}
|
||||||
|
|
||||||
class UnitSpec {
|
class UnitSpec extends FormulaElement {
|
||||||
final String name;
|
final String name;
|
||||||
final String baseUnit;
|
final String baseUnit;
|
||||||
final String symbol;
|
final String symbol;
|
||||||
|
|
@ -217,7 +219,7 @@ class VariableSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Formula {
|
class Formula extends FormulaElement {
|
||||||
final String name;
|
final String name;
|
||||||
final String? description;
|
final String? description;
|
||||||
final List<VariableSpec> input;
|
final List<VariableSpec> input;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue