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

Improve demos #33

Merged
merged 4 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ All of the following fields may be missing or undefined, i.e., they're all optio
1. `repoName`: repository name (if available)
1. `filename`: filename string (if available)
1. `lineNumber`: A one-based line number in the file (if available)
1. `characterIndex`: A zero-based integer character index which indicates the position of the error in the given text (line or field) (if available)
1. `extract`: An extract (if available) of the checked text which indicates the area containing the problem. Where helpful, some character substitutions have already been made, for example, if the notice is about spaces, it is generally helpful to display spaces as a visible character in an attempt to best highlight the issue to the user. (The length of the extract defaults to ten characters, but is settable as an option.)
1. `characterIndex`: A **zero-based** integer character index which indicates the position of the error in the given text (line or field) (if available)
1. `extract`: An excerpt (if available) from the checked text which indicates the area containing the problem. Where helpful, some character substitutions have already been made, for example, if the notice is about spaces, it is generally helpful to display spaces as a visible character in an attempt to best highlight the issue to the user. (The length of the extract defaults to ten characters, but is settable as an option.)
1. `location`: A string indicating the context of the notice, e.g., "in line 17 of 'someBook.usfm'". (Still not completely sure what should be left in this string now that we have added optional `filename`, `repoName`, `lineNumber` fields.)

Keeping our notices in this format, rather than the simplicity of just saving an array of single strings, allows the above *notice components* to be processed at a higher level, e.g., to allow user-controlled filtering, sorting, etc. The default is to funnel them all through the supplied `processNoticesToErrorsWarnings` function (in demos/notice-processing-functions.fs) which does the following:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "uw-content-validation",
"description": "Functions for Checking Door43.org Scriptural Content/Resources.",
"version": "0.8.9",
"version": "0.8.10_alpha3",
"private": false,
"homepage": "https://unfoldingword.github.io/uw-content-validation/",
"repository": {
Expand Down
107 changes: 55 additions & 52 deletions src/core/annotation-row-check.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/core/annotation-row-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const lineA9 = "1:9\tha33\t\t\t0\tIt was so\t“It happened like that” or “T
const data = {
// You can choose any of the above lines here
// (to demonstrate differing results)
languageCode: 'en',
annotationType: 'TN',
tableLineName : 'lineA9',
tableLine : lineA9,
Expand All @@ -47,7 +48,7 @@ const data = {
}

function CheckAnnotationRow(props) {
const { annotationType, bookID, C, V, tableLine, tableLineName, givenLocation } = props.data;
const { languageCode, annotationType, bookID, C, V, tableLine, tableLineName, givenLocation } = props.data;

const [results, setResults] = useState(null);

Expand All @@ -58,7 +59,7 @@ function CheckAnnotationRow(props) {
(async () => {
// Display our "waiting" message
setResults(<p style={{ color: 'magenta' }}>Checking {tableLineName} <b>{bookID}</b>…</p>);
const rawResults = await checkAnnotationTSVDataRow(annotationType, tableLine, bookID, C, V, givenLocation);
const rawResults = await checkAnnotationTSVDataRow(languageCode, annotationType, tableLine, bookID, C, V, givenLocation);
setResults(
<div>
<b>Check</b> {tableLineName}: "{tableLine.substr(0,256)}…"<br/><br/>
Expand Down
6 changes: 3 additions & 3 deletions src/core/annotation-table-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const EXPECTED_TN_HEADING_LINE = 'Reference\tID\tTags\tSupportReference\tQuote\t
const DEFAULT_EXTRACT_LENGTH = 10;


async function CheckAnnotationRows(annotationType, bookID, filename, tableText, givenLocation, optionalCheckingOptions) {
async function CheckAnnotationRows(languageCode, annotationType, bookID, filename, tableText, givenLocation, optionalCheckingOptions) {
/* This function is optimised for checking the entire file, i.e., all rows.

It also has the advantage of being able to compare one row with the previous one.
Expand All @@ -19,7 +19,7 @@ async function CheckAnnotationRows(annotationType, bookID, filename, tableText,

Returns a result object containing a successList and a noticeList
*/
// console.log(`CheckAnnotationRows(${annotationType}, ${bookID}, ${tableText.length}, ${location},${JSON.stringify(optionalCheckingOptions)})…`);
// console.log(`CheckAnnotationRows(${languageCode}, ${annotationType}, ${bookID}, ${tableText.length}, ${givenLocation},${JSON.stringify(optionalCheckingOptions)})…`);
let ourLocation = givenLocation;
if (ourLocation && ourLocation[0] !== ' ') ourLocation = ` ${ourLocation}`;
// if (bookID) ourLocation = ` in ${bookID}${ourLocation}`;
Expand Down Expand Up @@ -99,7 +99,7 @@ async function CheckAnnotationRows(annotationType, bookID, filename, tableText,
const [C, V] = reference.split(':')

// Use the row check to do most basic checks
const firstResult = await checkAnnotationTSVDataRow(annotationType, lines[n], bookID, C, V, ourLocation, optionalCheckingOptions);
const firstResult = await checkAnnotationTSVDataRow(languageCode, annotationType, lines[n], bookID, C, V, ourLocation, optionalCheckingOptions);
// Choose only ONE of the following
// This is the fast way of append the results from this field
// result.noticeList = result.noticeList.concat(firstResult.noticeList);
Expand Down
11 changes: 6 additions & 5 deletions src/core/annotation-table-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ These raw notice components can then be filtered and/or sorted as required by th

```js
import React, { useState, useEffect } from 'react';
import checkAnnotationTSVText from './annotation-table-check';
import checkAnnotationRows from './annotation-table-check';
import { RenderLines, RenderRawResults } from '../demos/RenderProcessedResults';

// Text samples
Expand Down Expand Up @@ -36,6 +36,7 @@ const lineA9 = "1:9\tha33\t\t\t\t0\t“It happened like that” or “That is wh
const data = {
// You can choose any of the above lines here
// (to demonstrate differing results)
languageCode: 'en',
annotationType: 'TN',
tableTextName : 'textG',
tableText : textG,
Expand All @@ -45,18 +46,18 @@ const data = {
}

function CheckAnnotationRows(props) {
const { annotationType, bookID, filename, tableText, tableTextName, givenLocation } = props.data;
const { languageCode, annotationType, bookID, filename, tableText, tableTextName, givenLocation } = props.data;

const [results, setResults] = useState(null);

// We need the following construction because checkAnnotationTSVText is an ASYNC function
// We need the following construction because checkAnnotationRows is an ASYNC function
useEffect(() => {
// Use an IIFE (Immediately Invoked Function Expression)
// e.g., see https://medium.com/javascript-in-plain-english/https-medium-com-javascript-in-plain-english-stop-feeling-iffy-about-using-an-iife-7b0292aba174
(async () => {
// Display our "waiting" message
setResults(<p style={{ color: 'magenta' }}>Checking {annotationType} for {tableTextName} <b>{bookID}</b>…</p>);
const rawResults = await checkAnnotationTSVText(annotationType, bookID, filename, tableText, givenLocation);
setResults(<p style={{ color: 'magenta' }}>Checking {languageCode} {annotationType} for {tableTextName} <b>{bookID}</b>…</p>);
const rawResults = await checkAnnotationRows(languageCode, annotationType, bookID, filename, tableText, givenLocation);
setResults(
<div>
<b>Check</b> {tableTextName}: "{tableText.substr(0,256)}…"<br/><br/>
Expand Down
Loading