Skip to content

Commit 9605edd

Browse files
committed
Sutra relations tried
1 parent 4c8b25b commit 9605edd

File tree

9 files changed

+371
-29
lines changed

9 files changed

+371
-29
lines changed

panini.php

Lines changed: 112 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,16 @@
6363
$number = $_GET['number']; // Verb number e.g. BU sattAyAm BvAdi has 01.0001 as number. Fetched via ajax.php
6464
$verbset = verbset_from_number($number); // bhvAdi, adAdi etc. Fetched via ajax.php
6565
$frontend = $_GET['frontend']; // Whether to display sUtras in frontend or not. Fetched via tiGanta.html
66-
//$frontend = '0';
6766
$type = $_GET['type'];
67+
$drop = $_GET['drop'];
6868
$letter = $_GET['letter'];
6969
$pr = $_GET['pratya'];
7070
$inprat = $_GET['pratyahara'];
71-
//$type = 'subanta';
7271
$removed_sutras = explode(',',$_GET['removed_sutras']);
7372
$removed_sutras = array_map('trim',$removed_sutras);
7473
droppedsutra($removed_sutras);
7574
global $storedata;
7675
if (!$verbset && $type==="tiGanta") { $verbset = scrape1($number,8,9,1)[0]; } // for overcoming issue in https://github.com/drdhaval2785/SanskritVerb/issues/97
77-
/* Now trying to make program equally compatible with commandline.
78-
The proposed structure is php tiGanta.php verb verbset lakAra tran upasarga vAcya
79-
defaults:
80-
verb - no default (mandatory to feed)
81-
verbset - 'none'
82-
lakAra - 'law'
83-
tran - 'SLP1'
84-
upasarga - ''
85-
vAcya - 'kartR'
86-
*/
8776
/* input from asyaprayatna.html */
8877
if ($type==="asyaprayatna")
8978
{
@@ -109,23 +98,26 @@
10998
$gender = "f";
11099
$type = "subanta";
111100
}
112-
// Input from commandline has to be in `php tiGanta.php 01.0001 law` format. Other details are fetched from verb number.
101+
// Input from commandline has to be in `php panini.php 01.0001 law` format. Other details are fetched from verb number.
113102
elseif (in_array($argv[2],array("law","liw","luw","lfw","sArvaDAtukalew","ArDaDAtukalew","low","laN","ASIrliN","viDiliN","luN","lfN")) || $test===1)
114103
{
115104
$number = $argv[1];
116105
$first = dhatu_from_number($number);
117106
$verbset = verbset_from_number($number);
118107
$lakAra = $argv[2];
119-
$tran = $argv[3];
120-
$us = $argv[4];
121-
$vAcya = $argv[5];
122-
$sanAdi = $argv[6];
108+
$removed_sutras = explode(',',$argv[3]);
109+
$removed_sutras = array_map('trim',$removed_sutras);
110+
$tran = $argv[4];
111+
$us = $argv[5];
112+
$vAcya = $argv[6];
113+
$sanAdi = $argv[7];
123114
if (!isset($argv[1])) { echo "Verb number is not entered"; exit; }
124115
if (!isset($argv[2])) { $lakAra = 'law'; }
125-
if (!isset($argv[3])) { $tran = 'SLP1'; }
126-
if (!isset($argv[4])) { $us = ''; }
127-
if (!isset($argv[5])) { $vAcya = 'kartR'; }
128-
if (!isset($argv[6])) { $sanAdi = ''; }
116+
if (!isset($argv[3])) { $removed_sutras = array(); }
117+
if (!isset($argv[4])) { $tran = 'SLP1'; }
118+
if (!isset($argv[5])) { $us = ''; }
119+
if (!isset($argv[6])) { $vAcya = 'kartR'; }
120+
if (!isset($argv[7])) { $sanAdi = ''; }
129121
$frontend="0";
130122
$type="tiGanta";
131123
}
@@ -135,6 +127,26 @@
135127
$logfile = fopen('verboutput//log.txt','a+');
136128
fputs($logfile,date('D, d M Y H:i:s')."\n");
137129
fputs($logfile,"verb = $first, gaNa = $verbset, lakAra = $lakAra, transliteration = $tran, vAcya = $vAcya, upasarga = $us\n");
130+
if ( (count($removed_sutras)===0 || $removed_sutras[0]==='') && isset($argv[0]))
131+
{
132+
$dropping = 1;
133+
$sutrarelationfile = fopen('sutrarelations/temp1.txt','w');
134+
}
135+
elseif ( (count($removed_sutras)===0||$removed_sutras[0]!=='') && isset($argv[0]))
136+
{
137+
$dropping = 2;
138+
$sutrarelationfile = fopen('sutrarelations/temp2.txt','w');
139+
}
140+
elseif (count($removed_sutras)===1 && $removed_sutras[0]==='' && !isset($argv[0]))
141+
{
142+
$dropping = 3;
143+
$sutrarelationfile = fopen('sutrarelations/temp3.txt','w');
144+
}
145+
elseif ( $removed_sutras[0]!=='' && !isset($argv[0]))
146+
{
147+
$dropping = 4;
148+
$sutrarelationfile = fopen('sutrarelations/temp4.txt','w');
149+
}
138150
}
139151
elseif ($type==='subanta') {
140152
mkdir ('nounoutput');
@@ -12373,7 +12385,7 @@
1237312385
if ($debug===1) {dibug('11710');}
1237412386
/* Final Display */
1237512387
if ($frontend!=="0")
12376-
{
12388+
{
1237712389
echo "<p class = sa >Final forms are :</p>\n";
1237812390
echo "<p class = sa >आखिरी रूप हैं :</p>\n";
1237912391
display(0);
@@ -12384,7 +12396,8 @@
1238412396
{
1238512397
$ou[] = implode(',',$text);
1238612398
}
12387-
12399+
$vidhisutras[] = vidhisutraseparator($storedata);
12400+
$allsutras[] = allsutras($storedata);
1238812401

1238912402
/* setting the $pada back to pratyaya for next use */
1239012403
$pada="pratyaya";
@@ -12417,16 +12430,92 @@
1241712430
/*$susinput = file_get_contents('suspectverbforms.txt');
1241812431
$susoutput = convert($susinput);
1241912432
file_put_contents('suspectverbforms_deva.txt',$susoutput);*/
12433+
if ($dropping===1||$dropping===3)
12434+
{
12435+
$uniquevidhisutras = array();
12436+
foreach ($vidhisutras as $value)
12437+
{
12438+
foreach ($value as $sutra)
12439+
{
12440+
if (!in_array($sutra,$uniquevidhisutras))
12441+
{
12442+
$uniquevidhisutras[] = $sutra;
12443+
}
12444+
}
12445+
}
12446+
$vidhisutrafile = fopen('sutrarelations/vidhi.txt','w');
12447+
fputs($vidhisutrafile,implode("\n",$uniquevidhisutras));
12448+
fclose($vidhisutrafile);
12449+
}
12450+
$uniqueallsutras = array();
12451+
foreach ($allsutras as $value)
12452+
{
12453+
foreach ($value as $sutra)
12454+
{
12455+
if (!in_array($sutra,$uniqueallsutras))
12456+
{
12457+
$uniqueallsutras[] = $sutra;
12458+
}
12459+
}
12460+
}
12461+
fputs($sutrarelationfile,implode("\n",$uniqueallsutras));
12462+
fclose($sutrarelationfile);
12463+
if ($dropping===2)
12464+
{
12465+
$exempted = difflister('sutrarelations/temp1.txt','sutrarelations/temp2.txt');
12466+
$added = difflister('sutrarelations/temp2.txt','sutrarelations/temp1.txt');
12467+
$difflog = fopen('sutrarelations/difflog1.txt','a');
12468+
$printstatement = implode(',',$removed_sutras).':'.$first.':'.$lakAra.':'.implode(',',$exempted).':'.implode(',',$added)."\n";
12469+
fputs($difflog,$printstatement);
12470+
fclose($difflog);
12471+
}
1242012472
}
1242112473
elseif ($type==="tiGanta")
1242212474
{
12475+
echo "yes";
1242312476
$ou = array_map('convert',$ou);
1242412477
tablemaker($ou);
1242512478
/* Closing the HTML */
1242612479
echo "</body>
1242712480
</html>";
1242812481
//fputs($outfile,"</body></html>");
1242912482
//fclose($outfile);
12483+
$uniquevidhisutras = array();
12484+
foreach ($vidhisutras as $value)
12485+
{
12486+
foreach ($value as $sutra)
12487+
{
12488+
if (!in_array($sutra,$uniquevidhisutras))
12489+
{
12490+
$uniquevidhisutras[] = $sutra;
12491+
}
12492+
}
12493+
}
12494+
$vidhisutrafile = fopen('sutrarelations/vidhi.txt','w');
12495+
fputs($vidhisutrafile,implode("\n",$uniquevidhisutras));
12496+
fclose($vidhisutrafile);
12497+
$uniqueallsutras = array();
12498+
foreach ($allsutras as $value)
12499+
{
12500+
foreach ($value as $sutra)
12501+
{
12502+
if (!in_array($sutra,$uniqueallsutras))
12503+
{
12504+
$uniqueallsutras[] = $sutra;
12505+
}
12506+
}
12507+
}
12508+
fputs($sutrarelationfile,implode("\n",$uniqueallsutras));
12509+
fclose($sutrarelationfile);
12510+
if ($dropping===4)
12511+
{
12512+
$exempted = difflister('sutrarelations/temp3.txt','sutrarelations/temp4.txt');
12513+
$added = difflister('sutrarelations/temp4.txt','sutrarelations/temp3.txt');
12514+
$difflog = fopen('sutrarelations/difflog2.txt','a');
12515+
$printstatement = implode(',',$removed_sutras).':'.$first.':'.$lakAra.':'.implode(',',$exempted).':'.implode(',',$added)."\n";
12516+
fputs($difflog,$printstatement);
12517+
fclose($difflog);
12518+
}
1243012519
}
1243112520
elseif ($type==="subanta")
1243212521
{

scripts/function.php

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ function ekAcobazo()
23742374
}
23752375

23762376
/* link_sutra function is courtesy of Funderburk Jim of sanskrit-lexicon. */
2377-
function link_sutra($s) {
2377+
function link_sutra($s,$relativepath="") {
23782378
/* $s is a string of form X.Y.Z where X,Y,Z are digits
23792379
Returns a string
23802380
<a href="Data/allsutrani/X.Y.Z.htm">X.Y.Z</a>
@@ -2389,7 +2389,14 @@ function link_sutra($s) {
23892389
$X=$parts[0];
23902390
$Y=$parts[1];
23912391
$Z=$parts[2];
2392-
$ans = "<a href=\"Data/allsutrani/$X.$Y.$Z.htm\" target='_blank'>$X.$Y.$Z</a>";
2392+
if ($relativepath!=="")
2393+
{
2394+
$ans = "<a href=\"$relativepath/Data/allsutrani/$X.$Y.$Z.htm\" target='_blank'>$X.$Y.$Z</a>";
2395+
}
2396+
else
2397+
{
2398+
$ans = "<a href=\"Data/allsutrani/$X.$Y.$Z.htm\" target='_blank'>$X.$Y.$Z</a>";
2399+
}
23932400
return $ans;
23942401
}
23952402

@@ -2832,11 +2839,11 @@ function zlu()
28322839
/* function storedata to store necessary information for display later on. */
28332840
function storedata($sutra_number,$style,$note)
28342841
{
2835-
global $text, $storedata, $frontend, $us, $removed_sutras;
2842+
global $text, $storedata, $us, $removed_sutras;
28362843
$text = one(array("++"),array("+"),0); // To remove double consecutive + signs before storing.
28372844
if (!in_array($style,array("pa","hn","st","red"))) { $style="sa"; }
28382845
if (!isset($note)) { $note=0; }
2839-
if ($frontend!=="0" && !in_array($sutra_number,$removed_sutras))
2846+
if (!in_array($sutra_number,$removed_sutras))
28402847
{
28412848
$storedata[]=array($text,$sutra_number,$style,$note,$us);
28422849
}
@@ -3414,7 +3421,41 @@ function generatedforms($list,$outputfile)
34143421
}
34153422
}
34163423
}
3417-
3424+
function vidhisutraseparator($storedata)
3425+
{
3426+
$vidhisutra = array();
3427+
foreach ($storedata as $value)
3428+
{
3429+
if ($value[2] === "sa")
3430+
{
3431+
$vidhisutra[] = $value[1];
3432+
}
3433+
}
3434+
$vidhisutra = array_unique($vidhisutra);
3435+
$vidhisutra = array_values($vidhisutra);
3436+
return $vidhisutra;
3437+
}
3438+
function allsutras($storedata)
3439+
{
3440+
foreach ($storedata as $value)
3441+
{
3442+
if ($value[2] !== "drop")
3443+
{
3444+
$allsutra[] = $value[1];
3445+
}
3446+
}
3447+
$allsutra = array_unique($allsutra);
3448+
$allsutra = array_values($allsutra);
3449+
return $allsutra;
3450+
}
3451+
function difflister($firstfile,$secondfile)
3452+
{
3453+
$firstlist = file($firstfile);
3454+
$firstlist = array_map('trim',$firstlist);
3455+
$secondlist = file($secondfile);
3456+
$secondlist = array_map('trim',$secondlist);
3457+
return array_diff($firstlist,$secondlist);
3458+
}
34183459

34193460
/* Functions which are not used in the code */
34203461
/* Function f to find the nth letter in the word */

scripts/sutrarelationdisplay.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
include 'function.php';
3+
include 'slp-dev.php';
4+
$data = file('../sutrarelations/difflog2.txt');
5+
$data = array_map('trim',$data);
6+
7+
function sutradisplay($sutra_number)
8+
{
9+
global $ASdata, $vdata, $miscdata, $paribhASAdata; global $upasarga_joined; global $us, $outfile, $otherdata; // bringing $text from main php function.
10+
$output = '';
11+
if (strpos($sutra_number,'~')!==false)
12+
{
13+
$matches = array_filter($otherdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
14+
$matches=array_values($matches);
15+
$int = explode(':',$matches[0]); // We presume that there would be only one match.
16+
$msg_no = $int[0];
17+
$msg_dev = $int[2];
18+
if ($msg_no === $sutra_number)
19+
{
20+
$output = $msg_dev;
21+
}
22+
}
23+
elseif (strpos($sutra_number,'@')!==false)
24+
{
25+
$matches = array_filter($paribhASAdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
26+
$matches=array_values($matches);
27+
$int = explode(':',$matches[0]); // We presume that there would be only one match.
28+
$msg_no = $int[0];
29+
$msg_dev = $int[2];
30+
if ($msg_no === $sutra_number)
31+
{
32+
$output = $msg_dev[$i];
33+
}
34+
}
35+
elseif (strpos($sutra_number,'-')===false && strpos($sutra_number,'.')!==false)
36+
{
37+
$matches = array_filter($ASdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
38+
$matches=array_values($matches);
39+
$int = explode(':',$matches[0]); // We presume that there would be only one such match.
40+
$sutra_no = $int[0];
41+
$sutra_dev = $int[2];
42+
if ($sutra_no === $sutra_number)
43+
{
44+
$output = $sutra_dev;
45+
}
46+
}
47+
elseif (strpos($sutra_number,'-')!==false && strpos($sutra_number,'.')!==false)
48+
{
49+
$matches = array_filter($vdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
50+
$matches=array_values($matches);
51+
$int = explode(':',$matches[0]);
52+
$vartika_no = $int[0];
53+
$sutra_dev = $int[1];
54+
if ($vartika_no === $sutra_number)
55+
{
56+
$output = convert($sutra_dev);
57+
}
58+
}
59+
else
60+
{
61+
$matches = array_filter($miscdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
62+
$matches=array_values($matches);
63+
$int = explode(':',$matches[0]);
64+
$vartika_no = $int[0];
65+
$sutra_dev = $int[1];
66+
if ($vartika_no === $sutra_number)
67+
{
68+
$output = convert($sutra_dev);
69+
}
70+
}
71+
if (isset($output) && $output!=='')
72+
{
73+
return $output."(".link_sutra($sutra_number,'..').")";
74+
}
75+
else
76+
{
77+
return "-----";
78+
}
79+
}
80+
81+
82+
foreach($data as $datum)
83+
{
84+
$parts = explode(':',$datum);
85+
echo convert($parts[1])."-".convert($parts[2])."<br/>\n";
86+
echo "If rule <b>".sutradisplay($parts[0])." didn't exist</b>, the following rules would <b>not have applied</b>.<br/>\n";
87+
$barredsutras = explode(',',$parts[3]);
88+
$barr = array();
89+
foreach ($barredsutras as $bar)
90+
{
91+
$barr[] = sutradisplay($bar);
92+
}
93+
echo implode(', ',$barr)."<br/>\n";
94+
echo "If rule <b>".sutradisplay($parts[0])." didn't exist</b>, the following new rules <b>would have applied</b>.<br/>\n";
95+
$newsutras = explode(',',$parts[4]);
96+
$neww = array();
97+
foreach ($newsutras as $new)
98+
{
99+
$neww[] = sutradisplay($new);
100+
}
101+
echo implode(', ',$neww)."<br/>\n";
102+
echo "<hr/>\n";
103+
}
104+
?>

sutrarelations/difflog2.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3.1.68:BU:law:3.4.113,3.1.68,1.3.8,7.3.84,6.1.78,6.1.97,7.3.101:7.3.88,6.4.77,8.3.55,8.3.57,8.3.59
2+
3.1.68:BU:law:3.4.113,3.1.68,1.3.8,7.3.84,6.1.78,6.1.97,7.3.101:7.3.88,6.4.77,8.3.55,8.3.57,8.3.59
3+
3.1.68:BU:law:3.4.113,3.1.68,1.3.8,7.3.84,6.1.78,6.1.97,7.3.101:7.3.88,6.4.77,8.3.55,8.3.57,8.3.59

0 commit comments

Comments
 (0)