Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/palette-json-generator-webapp #25

Merged

Conversation

klown
Copy link
Contributor

@klown klown commented Oct 28, 2024

A web-app for entering glosses, BCI AV IDs, and svg builder strings to produce and save a palette.

The main point is to make it easier than the previous way to make palettes by using text editor to edit the JSON description file directly. The previous way was time consuming and very error prone. The web-app approach allows most of the generation of the JSON to be automated, and allows the user to later tweak the JSON file as necessary.

This branch was originally created based on the code for PR #21, but incorporated @cindyli's script into user interface. It's not clear if this should be directly merged with the main branch or merged into the feat/palette-json-generator script branch first.

cindyli and others added 23 commits August 3, 2023 13:45
- uses `fetch()` to retrieve the blissay ID map,
- uses `fetch()` to retrieve W3C's bliss gloss .json file,
- UUID for each cell is prepended with the cell's label,
- generates an "Unknown" cell for errors, to be fixed manually,
- outputs a palette file with problem cells indicated as such.
- use local copy of `bliss_symbol_explanations.json`,
- `String.include()` will sometimes match many glosses.  The script
  now outputs all the matches found to the console and uses the first
  match in the generated palette
- for no match found, outputs a cell with label "NOT FOUND" and Bliss
  word for "not found".
@klown klown requested a review from cindyli October 28, 2024 13:57
README.md Outdated
## Utility Scripts

- [Load a document into a vector databbase (`scripts/loadDocIntoVectorDb.js`)](./scripts/loadDocIntoVectorDb.js)
- [Generate a palette JSON file (`scripts/paletteJsonGenerator.js`)](./scripts/loadDocIntoVectorDb.js)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"paletteJsonGenerator.js" is not in the "./scripts" directory. Did you forget to clean up this line after making the generator an app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I'll remove it.


Once the development server is running, open this `localhost` url from within a
browser:
[`http://localhost:5173/apps/palette-generator/palette-generator.html`](http://localhost:5173/apps/palette-generator/palette-generator.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming "palette-generator.html" to "index.html" so that accessing "http://localhost:5173/apps/palette-generator/" will automatically load the index page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the entry page has been renamed to "index.html", the link and text should be changed to remove "palette-generator.html".

row of the palette cells. Spaces are used for separate cells so the text used
to specify a cell cannot contain any spaces.

There are three types of input allowed here:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You listed four types below. Change "three types" to "four types" in this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

the label "cross hatches"; and "23641LABEL:ruin" will give "ruin" as the label
instead of the official gloss "ruin,wreck,wreckage\_(building)\_(1)".

The SVG string is marked by "SVG:" at the beginning of the string and ":SVG" at
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide an example of using the SVG string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added two examples. But, I am not going to explain the full syntax of svg builder strings. That should be in the svg-builder project, but there is no documentation there. And, I don't know the full specification. :-(

### Save Palette

Clicking the "Save palette" button will export a palette definition JSON file
and save it into the user's "Downloads" folder. The name of the file will be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user's computer doesn't hae a "Downloads" folder. Is this a browser specific configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The code itself does not include the name "Downloads" or the name of any other folder. An url is created that the browser understands, but is meaningless to me. The file ends up in the folder that has been set as the browser's download folder. Users can set this to something other than "Downloads", in which case the palette will be saved based on that browser setting.

I will reword it to say, '.. and saved to disk where the browser saves file downloads, typically the "Downloads" folder.'

// Initialize any globals used elsewhere in the code.
await initAdaptivePaletteGlobals("paletteDisplay");
await fetchBlissGlossJson();
let currentPaletteName = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook for currentPaletteName is probably wrong. The save button doesn't save the given palette name. The clear button doesn't clear the palette name too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a bug here and fixed it, but I have not addressed your comment fully:

The save button doesn't save the given palette name.

It does after the fix, but there is still an edge case where (1) the palette is generated, (2) the user changes the name in the text field, and then (3) clicks the "Save" button. In that case, the file is saved according the name in the text field when the palette was generated, not the just-changed text field For this case, there needs to be an event handler for watching changes in the text field and adjusting various objects. I'm working on that.

The clear button doesn't clear the palette name too.

I don't think it should clear the name in the text field. If a palette has been generated, but there are mistakes, and all the user wants to do is clear it, fix the mistake(s), and re-generate, then they should not have to re-enter the name. Their intent is to change the contents of the palette, not the name. When they do want to change the name, then it's relatively simple to click on the text field and give it a new name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should clear the name in the text field.

Thanks for the clarification, and I agree.

const LABEL_MARKER = "LABEL:";

// Configurable options -- ideally provided by the UI
const palette_name = "No name Palette";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default palette name on the UI is "palette". Would be nice to sync up the default value of palette_name variable and the one on the UI.

Copy link
Contributor Author

@klown klown Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I will get the contents of the name text field and pass it into the generator function.

const type = "ActionBmwCodeCell";

// Special encodings for labels that don't follow the standard mapping
const specialEncodings = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README probably should include the usage of this specialEncodings. Or, with introducing the LABEL: feature, this handling can be removed from the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to remove it now. But, just in case, what did you intend it for? Do the SVG: and LABEL: features cover that purpose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this special handling can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the definition and the use of specialEncodings?

List the items in each row, one line per row. Each row consists of a set
of glosses separated by a space.
</p>
<label for="glossInput">Glosses:</label><br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label for the text area to receive BCI-AV-ID, glosses, SVGs etc should no longer be "Glosses" since it accepts a lot more than glosses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll come up with a better name.

const BLANK_CELL_LABEL = "BLANK";
const SVG_PREFIX = "SVG:";
const SVG_SUFFIX = ":SVG";
const LABEL_MARKER = "LABEL:";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I input this line in the "Glosses" text area:

BLANK 18267LABEL:aaa induction

to alter the label for a symbol. I got this error in the error section: "BciAvId not found for label: induction". Moving the "LABEL:" marker to the last "induction" gloss reports the same error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That string specifies three cells: a blank one, one for a plus sign labelled "aaa" and a cell whose gloss is "induction" or contains the word induction. "Induction" does not match any gloss and that is why there is an error. Checking blissary.com with "induction" gives "No results found." The result is as expected. Moving the LABEL marker won't change the result.

There was some text in the README explaining that spaces are used as a separator to indicate the string to use for a cell. I've added more warnings to that effect including that LABEL: strings cannot contain spaces and to use an underscore if a space is desired. Specifically, if the label for the plus sign was supposed to be "aaa induction", then you write it this way:

BLANK 18267LABEL:aaa_induction

That gives two cells, a blank and a plus with the label "aaa induction".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. The error is reported correctly. I mistakenly thought it was related to the "LABEL" marker.

strings that are parsed by the svg builder. If the string "LABEL:*label\_text"
occurs immediately before the closing ":SVG" marker, it will be used as the
label for the cell, and is truncated from the rest of the string before the
remainder is sent to the builder. The rules for the syntax of this "LABEL" is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with using "LABEL" with "SVG" marker. This string SVG:14183,"/",25777,"/","W8W:0,8":SVGLABEL:aaa leads to an error: "BciAvId not found for label: SVG:14183,"/",25777,"/","W8W:0,8":SVG". Did I combine the "SVG" and "LABEL" correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoting from the README with emphasis:

If the string "LABEL:*label_text" occurs immediately before the closing ":SVG" marker,

So your example should be SVG:14183,"/",25777,"/","W8W:0,8","LABEL:aaa":SVG

However, that's different from the two other cases of an ID or a gloss-string, where the LABEL: is appended to the ID or string. I think it should be the same regardless of the input. I have re-written the processing so that your example works, and the old way is now illegal.

@cindyli
Copy link
Contributor

cindyli commented Oct 31, 2024

It would be helpful for users if you could add a small helper section next to the "Glosses" text field on the app interface. This area could provide quick explanations or examples of available markers like SVG, LABEL, and BLANK. I found I often doubt if I'm using these markers correctly and have to check README frequently.

@klown
Copy link
Contributor Author

klown commented Nov 4, 2024

@cindyli wrote:

It would be helpful for users if you could add a small helper section next to the "Glosses" text field on the app interface. This area could provide quick explanations or examples of available markers like SVG, LABEL, and BLANK. I found I often doubt if I'm using these markers correctly and have to check README frequently.

I added one but in a way that allows users to pop it open as needed and then hide it. I used the details/summary technique. I have written and re-written the text for it, and am still not satisfied. But, I have to stop at some point, so here it is.

I think I addressed all of your comments -- ready for another review, thanks.


Once the development server is running, open this `localhost` url from within a
browser:
[`http://localhost:5173/apps/palette-generator/palette-generator.html`](http://localhost:5173/apps/palette-generator/palette-generator.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the entry page has been renamed to "index.html", the link and text should be changed to remove "palette-generator.html".

Comment on lines 178 to 180
// dd = document.createElement("dd");
// dl.append(dd);
// dd.innerText = match.label;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, no longer needed.

const type = "ActionBmwCodeCell";

// Special encodings for labels that don't follow the standard mapping
const specialEncodings = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the definition and the use of specialEncodings?

if (matches.length === 0) {
throw new Error(`BciAvId not found for label: ${label}`);
}
console.log("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall this line be removed?

Copy link
Contributor Author

@klown klown Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was meant to output a blank line to separate the matches logged on the console. But in FF it insists on printing <empty string> which is not a blank line. I switched it to console.log("\n"); and that does print a blank line. Then I took it out completely, and the logged matches are readable even without a separating blank line. So, I ended up simply removing it.

@klown
Copy link
Contributor Author

klown commented Nov 6, 2024

@cindyli, I've addressed you last comments. I also added a new <select> element to allow users to choose the cell type. However one type, the ContentBmwEncoding cell type, does not render well. I am investigating.

Nonetheless, ready for another review.

@cindyli
Copy link
Contributor

cindyli commented Nov 6, 2024

The pull request looks great. I will wait for the fix of the rendering of the ContentBmwEncoding cell type.

@klown
Copy link
Contributor Author

klown commented Nov 6, 2024

I did manage to render ContentBmwEncoding by setting up the changeEncodingContents signal correctly. However, since the display area is a palette and not an content area, each cell is treated as a content area and all of the bliss symbols are shown in every cell. It looks bizarre.

Then I realized that the palette json file to be saved should never have cells of type ContentBmwEncoding. So, since this is about palette generation and not content generation, the select is set up so that ContentBmwEncoding is unavailable.

Let me know what you think.

@cindyli
Copy link
Contributor

cindyli commented Nov 6, 2024

Then I realized that the palette json file to be saved should never have cells of type ContentBmwEncoding. So, since this is about palette generation and not content generation, the select is set up so that ContentBmwEncoding is unavailable.

I agree this is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants