Skip to content

Commit

Permalink
more realistic implementation of words
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldangeofficial committed Apr 16, 2023
1 parent 0bcb1c3 commit 4d5160c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"BODMAS"
]
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a parser built in JavaScript that can parse arithmetic operations writte

## Input 1

"10 बेरीज 2 गुणाकार 3 वजाबाकी 4 भागाकार 2"
"10 अधिक 2 गुणिले 3 वजा 4 भागिले 2"

This input can be interpreted as the expression:

Expand All @@ -18,7 +18,7 @@ and the output will be 14

## Input 2

"10.5 बेरीज 2 गुणाकार (3 वजाबाकी 4) भागाकार 2.5"
"10.5 अधिक 2 गुणिले (3 वजा 4) भागिले 2.5"

This input can be interpreted as the expression:

Expand All @@ -28,7 +28,7 @@ and the output will be 9.7

## Input 3

"10.5बेरीज2गुणाकार(3वजाबाकी4)भागाकार2.5"
"10.5अधिक2गुणिले(3वजा4)भागिले2.5"

This input can be interpreted as the expression:

Expand All @@ -38,7 +38,7 @@ and the output will be 9.7

## Input 4

"16 वजाबाकी 8 बेरीज 14 भागाकार 2"
"16 वजा 8 अधिक 14 भागिले 2"

This input can be interpreted as the expression:

Expand All @@ -48,7 +48,7 @@ and the output will be 15

## Input 5

"16 वजाबाकी (8 बेरीज 14) भागाकार 2"
"16 वजा (8 अधिक 14) भागिले 2"

This input can be interpreted as the expression:

Expand All @@ -58,7 +58,7 @@ and the output will be 5

## Input 6

"16.5बेरीज2.5गुणाकार(3वजाबाकी4)भागाकार2.5"
"16.5अधिक2.5गुणिले(3वजा4)भागिले2.5"

This input can be interpreted as the expression:

Expand All @@ -68,7 +68,7 @@ and the output will be 15.5

## Input 7

"1बेरीज2बेरीज3"
"1अधिक2अधिक3"

This input can be interpreted as the expression:

Expand Down
16 changes: 8 additions & 8 deletions algo.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Parser {
}

replaceWords(str) {
const wordsToReplace = ['बेरीज', 'वजाबाकी', 'गुणाकार', 'भागाकार'];
const wordsToReplace = ['अधिक', 'वजा', 'गुणिले', 'भागिले'];
const replacementWords = ['A', 'S', 'M', 'D'];
for (let i = 0; i < wordsToReplace.length; i += 1) {
str = str.replaceAll(wordsToReplace[i], replacementWords[i]);
Expand Down Expand Up @@ -87,13 +87,13 @@ class Parser {
}
}

const input1 = '10 बेरीज 2 गुणाकार 3 वजाबाकी 4 भागाकार 2'; // '10 + 2 * 3 - 4 / 2'
const input2 = '10.5 बेरीज 2 गुणाकार (3 वजाबाकी 4) भागाकार 2.5'; // '10.5 + 2 * (3 - 4) / 2.5'
const input3 = '10.5बेरीज2गुणाकार(3वजाबाकी4)भागाकार2.5'; // '10.5+2*(3-4)/2.5'
const input4 = '16 वजाबाकी 8 बेरीज 14 भागाकार 2'; // '16 - 8 + 14 / 2'
const input5 = '16 वजाबाकी (8 बेरीज 14) भागाकार 2'; // '16 - (8 + 14) / 2'
const input6 = '16.5बेरीज2.5गुणाकार(3वजाबाकी4)भागाकार2.5'; // '16.5+2.5*(3-4)/2.5'
const input7 = '1बेरीज2बेरीज3'; // '1+2+3'
const input1 = '10 अधिक 2 गुणिले 3 वजा 4 भागिले 2'; // '10 + 2 * 3 - 4 / 2'
const input2 = '10.5 अधिक 2 गुणिले (3 वजा 4) भागिले 2.5'; // '10.5 + 2 * (3 - 4) / 2.5'
const input3 = '10.5अधिक2गुणिले(3वजा4)भागिले2.5'; // '10.5+2*(3-4)/2.5'
const input4 = '16 वजा 8 अधिक 14 भागिले 2'; // '16 - 8 + 14 / 2'
const input5 = '16 वजा (8 अधिक 14) भागिले 2'; // '16 - (8 + 14) / 2'
const input6 = '16.5अधिक2.5गुणिले(3वजा4)भागिले2.5'; // '16.5+2.5*(3-4)/2.5'
const input7 = '1अधिक2अधिक3'; // '1+2+3'

const parser1 = new Parser(input1);
const parser2 = new Parser(input2);
Expand Down
16 changes: 8 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ <h1>Marathi Arithmetic Parser</h1>
</div>
<hr>
<label for="input-expression" class="input-label">Enter the expression in Marathi:</label>
<input type="text" id="input-expression" class="input-field" placeholder="e.g. 10 बेरीज 2 गुणाकार 3 वजाबाकी 4 भागाकार 2">
<input type="text" id="input-expression" class="input-field" placeholder="e.g. 10 अधिक 2 गुणिले 3 वजा 4 भागिले 2">
<button id="parse-btn" class="btn">Parse</button>
<label for="output-result" class="output-label">Result:</label>
<input type="text" id="output-result" class="output-field" readonly>
<p>Examples:</p>
<ul>
<li>10 बेरीज 2 गुणाकार 3 वजाबाकी 4 भागाकार 2</li>
<li>10.5 बेरीज 2 गुणाकार (3 वजाबाकी 4) भागाकार 2.5</li>
<li>10.5बेरीज2गुणाकार(3वजाबाकी4)भागाकार2.5</li>
<li>16 वजाबाकी 8 बेरीज 14 भागाकार 2</li>
<li>16 वजाबाकी (8 बेरीज 14) भागाकार 2</li>
<li>16.5बेरीज2.5गुणाकार(3वजाबाकी4)भागाकार2.5</li>
<li>1बेरीज2बेरीज3</li>
<li>10 अधिक 2 गुणिले 3 वजा 4 भागिले 2</li>
<li>10.5 अधिक 2 गुणिले (3 वजा 4) भागिले 2.5</li>
<li>10.5अधिक2गुणिले(3वजा4)भागिले2.5</li>
<li>16 वजा 8 अधिक 14 भागिले 2</li>
<li>16 वजा (8 अधिक 14) भागिले 2</li>
<li>16.5अधिक2.5गुणिले(3वजा4)भागिले2.5</li>
<li>1अधिक2अधिक3</li>
</ul>
</div>

Expand Down
2 changes: 1 addition & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Parser {
}

replaceWords(str) {
const wordsToReplace = ["बेरीज", "वजाबाकी", "गुणाकार", "भागाकार"];
const wordsToReplace = ["अधिक", "वजा", "गुणिले", "भागिले"];
const replacementWords = ["A", "S", "M", "D"];
for (let i = 0; i < wordsToReplace.length; i += 1) {
str = str.replaceAll(wordsToReplace[i], replacementWords[i]);
Expand Down

0 comments on commit 4d5160c

Please sign in to comment.