Skip to content

Commit

Permalink
Sutra relations tried
Browse files Browse the repository at this point in the history
  • Loading branch information
drdhaval2785 committed Mar 13, 2016
1 parent 4c8b25b commit 9605edd
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 29 deletions.
135 changes: 112 additions & 23 deletions panini.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,16 @@
$number = $_GET['number']; // Verb number e.g. BU sattAyAm BvAdi has 01.0001 as number. Fetched via ajax.php
$verbset = verbset_from_number($number); // bhvAdi, adAdi etc. Fetched via ajax.php
$frontend = $_GET['frontend']; // Whether to display sUtras in frontend or not. Fetched via tiGanta.html
//$frontend = '0';
$type = $_GET['type'];
$drop = $_GET['drop'];
$letter = $_GET['letter'];
$pr = $_GET['pratya'];
$inprat = $_GET['pratyahara'];
//$type = 'subanta';
$removed_sutras = explode(',',$_GET['removed_sutras']);
$removed_sutras = array_map('trim',$removed_sutras);
droppedsutra($removed_sutras);
global $storedata;
if (!$verbset && $type==="tiGanta") { $verbset = scrape1($number,8,9,1)[0]; } // for overcoming issue in https://github.com/drdhaval2785/SanskritVerb/issues/97
/* Now trying to make program equally compatible with commandline.
The proposed structure is php tiGanta.php verb verbset lakAra tran upasarga vAcya
defaults:
verb - no default (mandatory to feed)
verbset - 'none'
lakAra - 'law'
tran - 'SLP1'
upasarga - ''
vAcya - 'kartR'
*/
/* input from asyaprayatna.html */
if ($type==="asyaprayatna")
{
Expand All @@ -109,23 +98,26 @@
$gender = "f";
$type = "subanta";
}
// Input from commandline has to be in `php tiGanta.php 01.0001 law` format. Other details are fetched from verb number.
// Input from commandline has to be in `php panini.php 01.0001 law` format. Other details are fetched from verb number.
elseif (in_array($argv[2],array("law","liw","luw","lfw","sArvaDAtukalew","ArDaDAtukalew","low","laN","ASIrliN","viDiliN","luN","lfN")) || $test===1)
{
$number = $argv[1];
$first = dhatu_from_number($number);
$verbset = verbset_from_number($number);
$lakAra = $argv[2];
$tran = $argv[3];
$us = $argv[4];
$vAcya = $argv[5];
$sanAdi = $argv[6];
$removed_sutras = explode(',',$argv[3]);
$removed_sutras = array_map('trim',$removed_sutras);
$tran = $argv[4];
$us = $argv[5];
$vAcya = $argv[6];
$sanAdi = $argv[7];
if (!isset($argv[1])) { echo "Verb number is not entered"; exit; }
if (!isset($argv[2])) { $lakAra = 'law'; }
if (!isset($argv[3])) { $tran = 'SLP1'; }
if (!isset($argv[4])) { $us = ''; }
if (!isset($argv[5])) { $vAcya = 'kartR'; }
if (!isset($argv[6])) { $sanAdi = ''; }
if (!isset($argv[3])) { $removed_sutras = array(); }
if (!isset($argv[4])) { $tran = 'SLP1'; }
if (!isset($argv[5])) { $us = ''; }
if (!isset($argv[6])) { $vAcya = 'kartR'; }
if (!isset($argv[7])) { $sanAdi = ''; }
$frontend="0";
$type="tiGanta";
}
Expand All @@ -135,6 +127,26 @@
$logfile = fopen('verboutput//log.txt','a+');
fputs($logfile,date('D, d M Y H:i:s')."\n");
fputs($logfile,"verb = $first, gaNa = $verbset, lakAra = $lakAra, transliteration = $tran, vAcya = $vAcya, upasarga = $us\n");
if ( (count($removed_sutras)===0 || $removed_sutras[0]==='') && isset($argv[0]))
{
$dropping = 1;
$sutrarelationfile = fopen('sutrarelations/temp1.txt','w');
}
elseif ( (count($removed_sutras)===0||$removed_sutras[0]!=='') && isset($argv[0]))
{
$dropping = 2;
$sutrarelationfile = fopen('sutrarelations/temp2.txt','w');
}
elseif (count($removed_sutras)===1 && $removed_sutras[0]==='' && !isset($argv[0]))
{
$dropping = 3;
$sutrarelationfile = fopen('sutrarelations/temp3.txt','w');
}
elseif ( $removed_sutras[0]!=='' && !isset($argv[0]))
{
$dropping = 4;
$sutrarelationfile = fopen('sutrarelations/temp4.txt','w');
}
}
elseif ($type==='subanta') {
mkdir ('nounoutput');
Expand Down Expand Up @@ -12373,7 +12385,7 @@
if ($debug===1) {dibug('11710');}
/* Final Display */
if ($frontend!=="0")
{
{
echo "<p class = sa >Final forms are :</p>\n";
echo "<p class = sa >आखिरी रूप हैं :</p>\n";
display(0);
Expand All @@ -12384,7 +12396,8 @@
{
$ou[] = implode(',',$text);
}

$vidhisutras[] = vidhisutraseparator($storedata);
$allsutras[] = allsutras($storedata);

/* setting the $pada back to pratyaya for next use */
$pada="pratyaya";
Expand Down Expand Up @@ -12417,16 +12430,92 @@
/*$susinput = file_get_contents('suspectverbforms.txt');
$susoutput = convert($susinput);
file_put_contents('suspectverbforms_deva.txt',$susoutput);*/
if ($dropping===1||$dropping===3)
{
$uniquevidhisutras = array();
foreach ($vidhisutras as $value)
{
foreach ($value as $sutra)
{
if (!in_array($sutra,$uniquevidhisutras))
{
$uniquevidhisutras[] = $sutra;
}
}
}
$vidhisutrafile = fopen('sutrarelations/vidhi.txt','w');
fputs($vidhisutrafile,implode("\n",$uniquevidhisutras));
fclose($vidhisutrafile);
}
$uniqueallsutras = array();
foreach ($allsutras as $value)
{
foreach ($value as $sutra)
{
if (!in_array($sutra,$uniqueallsutras))
{
$uniqueallsutras[] = $sutra;
}
}
}
fputs($sutrarelationfile,implode("\n",$uniqueallsutras));
fclose($sutrarelationfile);
if ($dropping===2)
{
$exempted = difflister('sutrarelations/temp1.txt','sutrarelations/temp2.txt');
$added = difflister('sutrarelations/temp2.txt','sutrarelations/temp1.txt');
$difflog = fopen('sutrarelations/difflog1.txt','a');
$printstatement = implode(',',$removed_sutras).':'.$first.':'.$lakAra.':'.implode(',',$exempted).':'.implode(',',$added)."\n";
fputs($difflog,$printstatement);
fclose($difflog);
}
}
elseif ($type==="tiGanta")
{
echo "yes";
$ou = array_map('convert',$ou);
tablemaker($ou);
/* Closing the HTML */
echo "</body>
</html>";
//fputs($outfile,"</body></html>");
//fclose($outfile);
$uniquevidhisutras = array();
foreach ($vidhisutras as $value)
{
foreach ($value as $sutra)
{
if (!in_array($sutra,$uniquevidhisutras))
{
$uniquevidhisutras[] = $sutra;
}
}
}
$vidhisutrafile = fopen('sutrarelations/vidhi.txt','w');
fputs($vidhisutrafile,implode("\n",$uniquevidhisutras));
fclose($vidhisutrafile);
$uniqueallsutras = array();
foreach ($allsutras as $value)
{
foreach ($value as $sutra)
{
if (!in_array($sutra,$uniqueallsutras))
{
$uniqueallsutras[] = $sutra;
}
}
}
fputs($sutrarelationfile,implode("\n",$uniqueallsutras));
fclose($sutrarelationfile);
if ($dropping===4)
{
$exempted = difflister('sutrarelations/temp3.txt','sutrarelations/temp4.txt');
$added = difflister('sutrarelations/temp4.txt','sutrarelations/temp3.txt');
$difflog = fopen('sutrarelations/difflog2.txt','a');
$printstatement = implode(',',$removed_sutras).':'.$first.':'.$lakAra.':'.implode(',',$exempted).':'.implode(',',$added)."\n";
fputs($difflog,$printstatement);
fclose($difflog);
}
}
elseif ($type==="subanta")
{
Expand Down
51 changes: 46 additions & 5 deletions scripts/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -2374,7 +2374,7 @@ function ekAcobazo()
}

/* link_sutra function is courtesy of Funderburk Jim of sanskrit-lexicon. */
function link_sutra($s) {
function link_sutra($s,$relativepath="") {
/* $s is a string of form X.Y.Z where X,Y,Z are digits
Returns a string
<a href="Data/allsutrani/X.Y.Z.htm">X.Y.Z</a>
Expand All @@ -2389,7 +2389,14 @@ function link_sutra($s) {
$X=$parts[0];
$Y=$parts[1];
$Z=$parts[2];
$ans = "<a href=\"Data/allsutrani/$X.$Y.$Z.htm\" target='_blank'>$X.$Y.$Z</a>";
if ($relativepath!=="")
{
$ans = "<a href=\"$relativepath/Data/allsutrani/$X.$Y.$Z.htm\" target='_blank'>$X.$Y.$Z</a>";
}
else
{
$ans = "<a href=\"Data/allsutrani/$X.$Y.$Z.htm\" target='_blank'>$X.$Y.$Z</a>";
}
return $ans;
}

Expand Down Expand Up @@ -2832,11 +2839,11 @@ function zlu()
/* function storedata to store necessary information for display later on. */
function storedata($sutra_number,$style,$note)
{
global $text, $storedata, $frontend, $us, $removed_sutras;
global $text, $storedata, $us, $removed_sutras;
$text = one(array("++"),array("+"),0); // To remove double consecutive + signs before storing.
if (!in_array($style,array("pa","hn","st","red"))) { $style="sa"; }
if (!isset($note)) { $note=0; }
if ($frontend!=="0" && !in_array($sutra_number,$removed_sutras))
if (!in_array($sutra_number,$removed_sutras))
{
$storedata[]=array($text,$sutra_number,$style,$note,$us);
}
Expand Down Expand Up @@ -3414,7 +3421,41 @@ function generatedforms($list,$outputfile)
}
}
}

function vidhisutraseparator($storedata)
{
$vidhisutra = array();
foreach ($storedata as $value)
{
if ($value[2] === "sa")
{
$vidhisutra[] = $value[1];
}
}
$vidhisutra = array_unique($vidhisutra);
$vidhisutra = array_values($vidhisutra);
return $vidhisutra;
}
function allsutras($storedata)
{
foreach ($storedata as $value)
{
if ($value[2] !== "drop")
{
$allsutra[] = $value[1];
}
}
$allsutra = array_unique($allsutra);
$allsutra = array_values($allsutra);
return $allsutra;
}
function difflister($firstfile,$secondfile)
{
$firstlist = file($firstfile);
$firstlist = array_map('trim',$firstlist);
$secondlist = file($secondfile);
$secondlist = array_map('trim',$secondlist);
return array_diff($firstlist,$secondlist);
}

/* Functions which are not used in the code */
/* Function f to find the nth letter in the word */
Expand Down
104 changes: 104 additions & 0 deletions scripts/sutrarelationdisplay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
include 'function.php';
include 'slp-dev.php';
$data = file('../sutrarelations/difflog2.txt');
$data = array_map('trim',$data);

function sutradisplay($sutra_number)
{
global $ASdata, $vdata, $miscdata, $paribhASAdata; global $upasarga_joined; global $us, $outfile, $otherdata; // bringing $text from main php function.
$output = '';
if (strpos($sutra_number,'~')!==false)
{
$matches = array_filter($otherdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
$matches=array_values($matches);
$int = explode(':',$matches[0]); // We presume that there would be only one match.
$msg_no = $int[0];
$msg_dev = $int[2];
if ($msg_no === $sutra_number)
{
$output = $msg_dev;
}
}
elseif (strpos($sutra_number,'@')!==false)
{
$matches = array_filter($paribhASAdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
$matches=array_values($matches);
$int = explode(':',$matches[0]); // We presume that there would be only one match.
$msg_no = $int[0];
$msg_dev = $int[2];
if ($msg_no === $sutra_number)
{
$output = $msg_dev[$i];
}
}
elseif (strpos($sutra_number,'-')===false && strpos($sutra_number,'.')!==false)
{
$matches = array_filter($ASdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
$matches=array_values($matches);
$int = explode(':',$matches[0]); // We presume that there would be only one such match.
$sutra_no = $int[0];
$sutra_dev = $int[2];
if ($sutra_no === $sutra_number)
{
$output = $sutra_dev;
}
}
elseif (strpos($sutra_number,'-')!==false && strpos($sutra_number,'.')!==false)
{
$matches = array_filter($vdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
$matches=array_values($matches);
$int = explode(':',$matches[0]);
$vartika_no = $int[0];
$sutra_dev = $int[1];
if ($vartika_no === $sutra_number)
{
$output = convert($sutra_dev);
}
}
else
{
$matches = array_filter($miscdata, function($var) use ($sutra_number) { return strpos($var,$sutra_number.":")!==false; });
$matches=array_values($matches);
$int = explode(':',$matches[0]);
$vartika_no = $int[0];
$sutra_dev = $int[1];
if ($vartika_no === $sutra_number)
{
$output = convert($sutra_dev);
}
}
if (isset($output) && $output!=='')
{
return $output."(".link_sutra($sutra_number,'..').")";
}
else
{
return "-----";
}
}


foreach($data as $datum)
{
$parts = explode(':',$datum);
echo convert($parts[1])."-".convert($parts[2])."<br/>\n";
echo "If rule <b>".sutradisplay($parts[0])." didn't exist</b>, the following rules would <b>not have applied</b>.<br/>\n";
$barredsutras = explode(',',$parts[3]);
$barr = array();
foreach ($barredsutras as $bar)
{
$barr[] = sutradisplay($bar);
}
echo implode(', ',$barr)."<br/>\n";
echo "If rule <b>".sutradisplay($parts[0])." didn't exist</b>, the following new rules <b>would have applied</b>.<br/>\n";
$newsutras = explode(',',$parts[4]);
$neww = array();
foreach ($newsutras as $new)
{
$neww[] = sutradisplay($new);
}
echo implode(', ',$neww)."<br/>\n";
echo "<hr/>\n";
}
?>
3 changes: 3 additions & 0 deletions sutrarelations/difflog2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
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.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
Loading

0 comments on commit 9605edd

Please sign in to comment.