Add a proper dart project for tooling

This commit is contained in:
minimo-io 2022-10-27 20:59:18 -03:00
parent 338a9b30ba
commit 204fc80140
15 changed files with 2799 additions and 73 deletions

6
mo-lunfardo/dart_tools/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages
# Conventional directory for build output.
build/

View File

@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

View File

@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.

View File

@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@ -0,0 +1,126 @@
#!/usr/bin/env dart
import 'dart:io';
import 'dart:convert';
import 'package:args/args.dart';
main(List<String> args) {
// var dir = Directory.current.path;
// var p = Platform.script.path;
final parser = ArgParser()
..addOption("action",
abbr: "a",
allowed: ["process", "merge"],
help:
"Provide an action to be executed on the source file with lunfardo words.")
..addOption("input",
abbr: "i",
help: "Path to the input text file containing the new lunfardo word")
..addOption("output",
abbr: "o",
help: "Output json file.",
defaultsTo: "dicc-processed-" +
DateTime.now().millisecondsSinceEpoch.toString() +
".json")
..addFlag("help",
abbr: "h",
negatable: false,
help: "Print help instructions for processing lunfardo word files.")
..addOption("input1",
help: "First input file to be merged. This needs an input2")
..addOption("input2", help: "Second input file to be merged with input1")
..addSeparator("=== LUNFARDO WORD PROCESSOR TOOL by minimo.io\n");
final parserResults = parser.parse(args);
if (parserResults.wasParsed("help") || !parserResults.wasParsed("action")) {
print(parser.usage);
exit(1);
}
if ("process" == parserResults["action"]) {
if (!parserResults.wasParsed("input")) {
print("Please provide an input file to process\n");
print(parser.usage);
exit(1);
}
print("> Trying to process new lunfardo words...");
File(parserResults["input"]).readAsString().then((String contents) {
String contentsWithNoLines = contents.replaceAll("\r", "");
List<String> words = contentsWithNoLines.split("\n");
List<Map<String, String>> distilledTerms = []; // final string of terms
for (var word in words) {
// var wordIndex = words.indexOf(word);
// if its only a number then its the page number from pdf and skip
if (isNumeric(word)) continue;
// capitalize
// word = word.capitalize();
if (word.contains(":")) {
List termList = word.split(":"); // [0]: term [1]: description
// add the term
distilledTerms.add({
't': termList[0],
'd': termList[1].toString().trim(),
's': termList.asMap().containsKey(2) ? termList[2] : ""
});
} else {
// if the following line does not have an : then its not a new term
// but a part of the previus one.
// here we should add the term to the previous.
// word in this case is just a line with the rest of the description
// print(word);
// get last element of the terms array
Map<String, String> lastElement = distilledTerms.last;
int lastElementIndex = distilledTerms.indexOf(distilledTerms.last);
lastElement["d"] = lastElement["d"].toString() + " " + word;
// replace for the now complete term description
distilledTerms[lastElementIndex] = lastElement;
}
}
print("> Yep, we did it! " +
distilledTerms.length.toString() +
" words processed.");
saveFile(json.encode(distilledTerms), parserResults["output"]);
});
}
if ("merge" == parserResults["action"]) {
if (!parserResults.wasParsed("input1")) {
print("Please provide a first input(1) file to merge\n");
print(parser.usage);
exit(1);
}
if (!parserResults.wasParsed("input2")) {
print("Please provide a second input(2) file to merge\n");
print(parser.usage);
exit(1);
}
print("> Let's do it! Trying to merge...");
}
// last dicc from folkloretradiciones.com.ar
}
bool isNumeric(String? s) {
if (s == null) {
return false;
}
return double.tryParse(s) != null;
}
void saveFile(String string, String output) async {
File file = File(output);
file.writeAsString(string);
}
extension StringExtension on String {
String capitalize() {
return "${this[0].toUpperCase()}${this.substring(1).toLowerCase()}";
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,3 @@
int calculate() {
return 6 * 7;
}

View File

@ -0,0 +1,327 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "47.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "4.7.0"
args:
dependency: "direct main"
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.17.0"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
coverage:
dependency: transitive
description:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.4"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.1"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
io:
dependency: transitive
description:
name: io
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.5"
lints:
dependency: "direct dev"
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.12"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
pool:
dependency: transitive
description:
name: pool
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.1"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.10"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
test:
dependency: "direct dev"
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.21.4"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.12"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.16"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "9.4.0"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.17.6 <3.0.0"

View File

@ -0,0 +1,14 @@
name: dart_tools
description: A sample command-line application.
version: 1.0.0
# homepage: https://www.example.com
environment:
sdk: '>=2.17.6 <3.0.0'
dependencies:
args: ^2.3.1
dev_dependencies:
lints: ^2.0.0
test: ^1.16.0

View File

@ -0,0 +1,8 @@
import 'package:dart_tools/dart_tools.dart';
import 'package:test/test.dart';
void main() {
test('calculate', () {
expect(calculate(), 42);
});
}

View File

@ -7,6 +7,8 @@ const App = Vue.createApp({
placeholder: 'Buscá che...', placeholder: 'Buscá che...',
searchQuery: '', searchQuery: '',
noResults: false, noResults: false,
showLoadMore: true,
loadMoreSlice: 100,
wordsJson: [] wordsJson: []
} }
}, },
@ -17,13 +19,18 @@ const App = Vue.createApp({
//return obj.t.toLowerCase().includes(term) || obj.d.toLowerCase().includes(term); //return obj.t.toLowerCase().includes(term) || obj.d.toLowerCase().includes(term);
// search only on terms not descriptions for it not to be so messy // search only on terms not descriptions for it not to be so messy
return obj.t.toLowerCase().includes(term); return obj.t.toLowerCase().includes(term);
},
loadMore(){
this.loadMoreSlice += 100;
if (this.loadMoreSlice >= this.wordsJson.length) this.showLoadMore = false;
} }
}, },
async mounted(){ async mounted(){
const res = await fetch("https://cdn.jsdelivr.net/gh/minimo-io/appticles@v0.0.2-5/mo-lunfardo/data/lunfardo-dict-es.json"); // const res = await fetch("https://cdn.jsdelivr.net/gh/minimo-io/appticles@v0.0.2-6/mo-lunfardo/data/lunfardo-dict-es.json");
// const res = await fetch("tools/dicc.json"); // const res = await fetch("tools/dicc.json");
// const res = await fetch("data/lunfardo-dict-es.json"); const res = await fetch("data/lunfardo-dict-es.json");
this.wordsJson = await res.json(); this.wordsJson = await res.json();
}, },
@ -38,7 +45,7 @@ const App = Vue.createApp({
filteredList() { filteredList() {
if (!this.searchQuery) { if (!this.searchQuery) {
//return this.listValues.slice(0, 10); //return this.listValues.slice(0, 10);
return this.listValues.slice(0, 50); return this.listValues.slice(0, this.loadMoreSlice);
} }
var filteredValues = this.listValues var filteredValues = this.listValues
.map((v) => { .map((v) => {

View File

@ -28,6 +28,7 @@
<ul class="mt-4"> <ul class="mt-4">
<li v-for="(data, index) in filteredList"><strong>{{ data.t }}</strong>: {{ data.d }}</li> <li v-for="(data, index) in filteredList"><strong>{{ data.t }}</strong>: {{ data.d }}</li>
</ul> </ul>
<button v-if="! searchQuery && showLoadMore" @click="loadMore">Cargar más</button>
</div> </div>
</div> </div>

View File

@ -1,70 +0,0 @@
#!/usr/bin/env dart
// process lunfardo dictionary raw file
// the process assumes the following structure: [term]:[description]
// https://github.com/minimo-io
// import 'dart:async';
import 'dart:io';
import 'dart:convert';
main(List<String> args) {
var dir = Directory.current.path;
var p = Platform.script.path;
File('dicc.txt').readAsString().then((String contents) {
String contentsWithNoLines = contents.replaceAll("\r", "");
List<String> words = contentsWithNoLines.split("\n");
List<Map<String, String>> distilledTerms = []; // final string of terms
for (var word in words) {
var wordIndex = words.indexOf(word);
// if its only a number then its the page number from pdf and skip
if (isNumeric(word)) continue;
// capitalize
// word = word.capitalize();
if (word.contains(":")) {
List termList = word.split(":"); // [0]: term [1]: description
// add the term
distilledTerms.add({
't': termList[0],
'd': termList[1].toString().trim(),
});
} else {
// if the following line does not have an : then its not a new term
// but a part of the previus one.
// here we should add the term to the previous.
// word in this case is just a line with the rest of the description
// print(word);
// get last element of the terms array
Map<String, String> lastElement = distilledTerms.last;
int lastElementIndex = distilledTerms.indexOf(distilledTerms.last);
lastElement["d"] = lastElement["d"].toString() + " " + word;
// replace for the now complete term description
distilledTerms[lastElementIndex] = lastElement;
}
}
saveFile(json.encode(distilledTerms));
});
}
bool isNumeric(String? s) {
if (s == null) {
return false;
}
return double.tryParse(s) != null;
}
void saveFile(String string) async {
File file = File(await "dicc.json");
file.writeAsString(string);
}
extension StringExtension on String {
String capitalize() {
return "${this[0].toUpperCase()}${this.substring(1).toLowerCase()}";
}
}