Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,133,774 members, 7,744,989 topics. Date: Thursday, 22 February 2024 at 07:05 PM

Sorting Out A Simple Text Dictionary With PHP - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Sorting Out A Simple Text Dictionary With PHP (5762 Views)

(2) (3) (4)

(1) (Reply) (Go Down)

Sorting Out A Simple Text Dictionary With PHP by dhtml(m): 11:13pm On Jul 20, 2014
I was trying to make a facebook post some minutes back, and here was the content of the post. Now, i was faced with a real dilema, this stuff needs to be sorted out. I was about doing copy and paste, and then i remember I was a programmer, so i decided to give PHP the dirty work

gbewiri - olee, thief

Ahere - Hut.
Akinkanju - Fearless fellow
Adunmaradan - Ebony
Akiesi - Notice
Alalubarika - Someone who is Blessed
Akalamagbo - Vulture
Apanimayoda - Literarily means someone that kills without sword (witches, slander..etc)
Abami- wierd
Aramanda- wonders
Amulumala - Endeavor
Akidanidani - Retard
Alantakun - Spider
Aramanda - Wonders/Magic
Amuludun - Socialite
Agunmaniye - Tall and Skinning/Obey the wind. a.k.a?:teu26:
Amohunmaworan - Television
Atapatadide - someone who has a poor begining
Atanpako - Thumb

Laakaye - WISDOM
Igunuko - that masquerade that rises and shrinks all the way to the earth mysteriously.

Janpata - Struggle
Ikuuku - Fist
Erujeje - Fearful

Janduku - Thugs/Gangster
Gidigbo - Rough Fight

Akiesi - attentive
Alalubarika- blessing/favor
Janduku- thug
Akalamagbo- some animal, dunno
Gidigbo- wrestling
Apanimayoda- traitor
Ebora - a spirit of the wild

peperempe - babe
Shaje - Wise (Local)
Alashakasha - Bad style

Alabahun - Tortoise
Alumogaji - can't remember this
S'abere dowo - Tailor
Agbejoro - Lawyer


Akiesi - Notice/being suspicious
Alalubarika - Blessing
Janduku - Rogue
Akalamagbo - Vulture
Gidigbo - Village square fight

Rogbodiyan - Strife
Jagidijagan - Troublesome


Borokini - Honorable person
Ajere - Announcer/PR
Ologini - Cat


Alabahun - Tortoise
Alumogaji - can't remember this
S'abere dowo - Tailor
Agbejoro- Lawyer

Gbeborun - Busy body- Gossiper

Agunbaniro: Yoruba translation of NYSC(a helper- Literarily means someone that helps you take of your load))

Amoniseni - who needs an enemy when that person is friend
Olojukokoro - Greedy
Isembaiye - Ancient/Historical - existed before our forefathers
Isekuse - Promiscious
Abanikedun - Mourner
Ogulutu - dumb ***
Ojurere - Favor

Ojuoro - either Waterlilly or Mistletoe
Osibata - a bird with long neck that floats on water (seriously)


Panshaga - Fornication
Agbere - Adultery
Agunbaniro- (i'm clueless)
Elenini - A pester, i think
Akitiyan - Effort
Aisiki - Someone's destiny/luck

Agabagebe - Hypocrite

Alupupu - Motorcycle

Igberiko - Area

aniyan - promise (has the same meaning like mo se ileri fun olorun)

Panshaga - Fornication
Agbere - Adultery
Agunbaniro- youth corper
Elenini - A pester
Akitiyan - Effort
Sababi -Destiny
Aisiki - Someone's destiny/luck
Aniyan - goal, what u wanna do or what u hope to do
Wombia - greedy,(someone who eats a lot)

Adaniway - Creator
Laakaiye - knowledge


Adaniwaye - God
Labare - Expression
Laakaiye - Senses
Sakani - Surroundings


Ijakadi - Wrestling
Abami - Weirdo, Strange being.
Ebora - Demonic beings
Gbewiri - Theif
Omidan - Lady
Didinrin - Dummy
Dadandidin - Stupid idiot
Salubata - Sanda


Ijakadi - fighting gidigbo
Ebora - strange/evil spirit
Irukerudo - perils

1 Like 1 Share

Re: Sorting Out A Simple Text Dictionary With PHP by dhtml(m): 11:15pm On Jul 20, 2014
Ah well, after about 17 lines of PHP code approximately 2 - 3 minutes later, here is what i got:
Not only was it sorted neatly, it also put the starting alphabet for each of the groups.

[Aa]
Abami = Weirdo, Strange being.
Abanikedun = Mourner
Adaniway = Creator
Adaniwaye = God
Adunmaradan = Ebony
Agabagebe = Hypocrite
Agbejoro = Lawyer
Agbere = Adultery
Agunbaniro = youth corper
Agunbaniro: Yoruba Translation Of NYSC(a Helper = Literarily means someone that helps you take of your load))
Agunmaniye = Tall and Skinning/Obey the wind. a.k.a?:teu26:
Ahere = Hut.
Aisiki = Someone's destiny/luck
Ajere = Announcer/PR
Akalamagbo = Vulture
Akidanidani = Retard
Akiesi = Notice/being suspicious
Akinkanju = Fearless fellow
Akitiyan = Effort
Alabahun = Tortoise
Alalubarika = Blessing
Alantakun = Spider
Alashakasha = Bad style
Alumogaji = can't remember this
Alupupu = Motorcycle
Amohunmaworan = Television
Amoniseni = who needs an enemy when that person is friend
Amuludun = Socialite
Amulumala = Endeavor
Aniyan = goal, what u wanna do or what u hope to do
Apanimayoda = traitor
Aramanda = Wonders/Magic
Atanpako = Thumb
Atapatadide = someone who has a poor begining

[Bb]
Borokini = Honorable person

[Dd]
Dadandidin = Stupid idiot
Didinrin = Dummy

[Ee]
Ebora = strange/evil spirit
Elenini = A pester
Erujeje = Fearful

[]
Gbewiri = Theif
Gidigbo = Village square fight

[Ii]
Igberiko = Area
Igunuko = that masquerade that rises and shrinks all the way to the earth mysteriously.
Ijakadi = fighting gidigbo
Ikuuku = Fist
Irukerudo = perils
Isekuse = Promiscious

[Jj]
Jagidijagan = Troublesome
Janduku = Rogue
Janpata = Struggle

[Ll]
Laakaiye = Senses
Laakaye = WISDOM
Labare = Expression

[Oo]
Ogulutu = dumb ***
Ojuoro = either Waterlilly or Mistletoe
Ojurere = Favor
Ologini = Cat
Olojukokoro = Greedy
Omidan = Lady
Osibata = a bird with long neck that floats on water (seriously)

[Pp]
Panshaga = Fornication
Peperempe = babe

[Rr]
Rogbodiyan = Strife

[Ss]
S'abere Dowo = Tailor
Sababi = Destiny
Sakani = Surroundings
Salubata = Sanda
Shaje = Wise (Local)

[Ww]
Wombia = greedy,(someone who eats a lot)
Re: Sorting Out A Simple Text Dictionary With PHP by dhtml(m): 11:16pm On Jul 20, 2014
The code in question:
<?php
header('Content-type:text/plain');
$y=trim(file_get_contents('yoruba.txt')); //retrieve entire raw text file containing the words in the unsorted pattern
$lines=explode("\n",$y); //split it into lines
foreach($lines as $line) {//loop through each line
$l=explode('-',$line); //break each line into an array based on the -
$l=array_map('trim',$l); //trim spaces on both word and meaning
$l[0]=ucwords($l[0]); //start word with uppercase for uniformity
if(count($l)==2) {$arr[$l[0]]=$l[1];} //the line trims out any line that does not conform to word - meaning such as empty lines
}
ksort($arr); //sort the word and meaning alphabetically using the key i.e. word
$boundary=""; //let us now display the clean result in alphabetical order and with no spaces
foreach($arr as $word=>$meaning) {
$b=substr($word,0,1);
if($b!=$boundary) {echo "\n".'['.$b.strtolower($b).']'."\n";$boundary=$b;}
echo "$word = $meaning\n";
}
?>
Re: Sorting Out A Simple Text Dictionary With PHP by IamGodzilla: 11:21pm On Jul 20, 2014
nice!

1 Like

Re: Sorting Out A Simple Text Dictionary With PHP by dhtml(m): 11:26pm On Jul 20, 2014
Thanks bro!

1 Like

Re: Sorting Out A Simple Text Dictionary With PHP by Olyboy16(m): 1:51am On Jul 21, 2014
Hmm...so these are dhtml's php codes..i c..nice work
Re: Sorting Out A Simple Text Dictionary With PHP by dhtml(m): 2:38am On Jul 21, 2014
Olyboy16: Hmm...so these are dhtml's php codes..i c..nice work
You got me laughing, are you trying to say their is something strange about my method of coding? I know i need to improve, thanks for the compliment though.
Re: Sorting Out A Simple Text Dictionary With PHP by Nobody: 6:58am On Jul 21, 2014
In The quiet words of a beginner: "Nice one Bro"..
Re: Sorting Out A Simple Text Dictionary With PHP by dhtml(m): 8:10am On Jul 21, 2014
Djangocode: In The quiet words of a beginner: "Nice one Bro"..
Thanks bro.
Re: Sorting Out A Simple Text Dictionary With PHP by logoscope(m): 12:31pm On Jul 21, 2014
Wow. cool. cool
Re: Sorting Out A Simple Text Dictionary With PHP by boomtube: 12:45pm On Jul 21, 2014
logoscope: Wow. cool. cool
Were you expecting like maybe a longer code?
Re: Sorting Out A Simple Text Dictionary With PHP by Olyboy16(m): 12:47pm On Jul 21, 2014
dhtml:
You got me laughing, are you trying to say their is something strange about my method of coding? I know i need to improve, thanks for the compliment though.

you deciphered my post already.. Now thats some real intelligence!!
Re: Sorting Out A Simple Text Dictionary With PHP by boomtube: 1:23pm On Jul 21, 2014
Olyboy16:
you deciphered my post already.. Now thats some real intelligence!!
Thanks, i appreciate that. . .dont mind the pirated ID
Re: Sorting Out A Simple Text Dictionary With PHP by logoscope(m): 7:23am On Jul 22, 2014
boomtube:
Were you expecting like maybe a longer code?
Nah, not really. I was impressed with the way he used PHP to solve a simple problem.
Re: Sorting Out A Simple Text Dictionary With PHP by asalimpo(m): 10:40am On Jul 22, 2014
Your code highlights design flaws of d php language.

1.) ambiguous data type syntax.
Scalars and compounds (list,arrays) indistiguishable!


$y = (get-file-content,"yoruba.txt"wink

wat data type is $y? (cant say by lookng at the variable declaration.


$lines = explode('\n',$y)
$l = explode('-',$line')

$lines is a compound type but u cant tell at declaration time?!
Same Q applies to $l?
If $l is an array wat datatype is $lines?




arr[$l[0]]

ok.? What kinda syntax is ths?




count($l)


this is for determg size of array, i guess.
But i thought php was OO compliant. This kinda procedural abomination should have been deprecated from d language a long time ago.!!
With facilities like this, php coders can spitout sloppy code ,part OO part procedural).
Re: Sorting Out A Simple Text Dictionary With PHP by dhtmlextreme(m): 8:53pm On Jul 22, 2014
@asalimpo, this code has been tested in latest version of PHP and has no errors (in fact it should work in all versions of php 3,4,5). If you do not understand the PHP rules that are involved, well, I can attempt to explain.

PHP/Javascript are different from C and Java where you need to declare a variable before use, and you dont have to stick to a particular type

$y='Seun';
$y=100.50;
$y=5;
$y=Array();
100% correct php code.

$y=trim(file_get_contents( => $y is created and assigned value at this point by the result of the function trim which is a string variable (standard php rule). As long as i do not attempt to use a variable such as y before declaration, i should never get an error in php

Following the same principles:
$lines = explode('\n',$y) => explode will split a string into an array, so $lines is created as an array and assigned the result

$l = explode('-',$line') -> this will create an array of a particular line of text, the array has a key/value (word/meaning) - both key and value are strings.

$l[0] will give the key of the array as explained above.

arr[$l[0]] - will give the value of the array since array(key) is used

count($l) will give the size of the array as you already guessed.

As for your procedural abominations, i dont know what you are talking about. I write standard codes as a PHP expert (both oop and procedural when required), but this is a very simple code as far as i am concerned.

2 Likes

Re: Sorting Out A Simple Text Dictionary With PHP by babatope88(m): 11:52pm On Jul 22, 2014
Oga plenty 4 here sha
Re: Sorting Out A Simple Text Dictionary With PHP by Olyboy16(m): 2:56pm On Jul 23, 2014
asalimpo: Your code highlights design flaws of d php language.

1.) ambiguous data type syntax.
Scalars and compounds (list,arrays) indistiguishable!


$y = (get-file-content,"yoruba.txt"wink

wat data type is $y? (cant say by lookng at the variable declaration.


$lines = explode('\n',$y)
$l = explode('-',$line')

$lines is a compound type but u cant tell at declaration time?!
Same Q applies to $l?
If $l is an array wat datatype is $lines?




arr[$l[0]]

ok.? What kinda syntax is ths?




count($l)


this is for determg size of array, i guess.
But i thought php was OO compliant. This kinda procedural abomination should have been deprecated from d language a long time ago.!!
With facilities like this, php coders can spitout sloppy code ,part OO part procedural).

"they must know me too. I sabi dis tin smal".. *yimu*
Re: Sorting Out A Simple Text Dictionary With PHP by dhtmlextreme(m): 8:15pm On Jul 23, 2014
Olyboy16: "they must know me too. I sabi dis tin smal".. *yimu*
You can get banned for YIMUing on this board o, berra be careful.
Re: Sorting Out A Simple Text Dictionary With PHP by Olyboy16(m): 9:58pm On Jul 23, 2014
[quote author=]
You can get banned for YIMUing on this board o, berra be careful.
[/quote]
Are you serious or jst kidding?
Re: Sorting Out A Simple Text Dictionary With PHP by asalimpo(m): 11:03pm On Jul 23, 2014
]@asalimpo, this code has been tested in latest version of PHP and has no errors (in fact it should work in all versions of php 3,4,5). If you do not understand the PHP rules that are involved, well, I can attempt to explain.

PHP/Javascript are different from C and Java where you need to declare a variable before use, and you dont have to stick to a particular type


100% correct php code.

$y=trim(file_get_contents( => $y is created and assigned value at this point by the result of the function trim which is a string variable (standard php rule). As long as i do not attempt to use a variable such as y before declaration, i should never get an error in php

Following the same principles:
$lines = explode('\n',$y) => explode will split a string into an array, so $lines is created as an array and assigned the result

$l = explode('-',$line') -> this will create an array of a particular line of text, the array has a key/value (word/meaning) - both key and value are strings.

$l[0:

will give the key of the array as explained above.

arr[$l[0]] - will give the value of the array since array(key) is used

count($l) will give the size of the array as you already guessed.

As for your procedural abominations, i dont know what you are talking about. I write standard codes as a PHP expert (both oop and procedural when required), but this is a very simple code as far as i am concerned.
the first issue i raised cud b ignored cuz php follows d trend of other dynamic languages (python,ruby,smalltalk,groovy)
.the fields dont display type information . This is also d case with static languages too. Though, type information is specified at creation time in static languages.
E.g
string[] countries = ...//some code
[] conveys type information about d field 'countries' . Som1 readg d code knows its an array , but later on in the code base he will need help to get this info.
Tht's y most languages hav ide's.

Countries = method1();

here, coder doesnt know what kind of field 'countries' is. Is it a scala,array,list,etc. Ide help needed.

But since this is d issue with 99.9 percnt of most modern langs, its accepted custom.
But, perl, a language tht inspires php appends type information to fields so tht at a glance a programmer can tell wat type (container type) of field he's dealg with. $ for scalas, @ for arrays and % for hashmaps.

2.
----
php allows the mixg of procedural and oop design styles in d same code base. oop is d more structured and disciplined approach. Ruby is purely oop, yet its dynamic.

E.g
count(list) - is a free floatg function,
so is explode(string)
etc.

Programmers invoke these in built functions, get d results and go on their way.
But because these functions work well as standalone entire code blocks cud b constructed purely from them, without any need for oop. Which creates a breed of quick and monolithic coders. The only modularity existg in situations like these is at d source file level. The files can b distributed.
As far as php keeps makg structural codg an alternatv to oop , it will keep breedg quick coders who go straight to d point , without botherg oop concepts but who'll keep churng hard to maintain huge piles of monolithc code.
Php shud come clean and break away from backward compatibility and make php a completely modular language.
Put count() in a list class.
Put explode() in a String /or StringUtility class.
Make modularity at the design level instead of at d source file level.

1 Like

Re: Sorting Out A Simple Text Dictionary With PHP by dhtmlextreme(m): 6:46am On Jul 24, 2014
Ah well, you are right in a way
Re: Sorting Out A Simple Text Dictionary With PHP by cyrielo(m): 10:20am On Jul 24, 2014
asalimpo: Your code highlights design flaws of d php language.
PHP is a dynamic and a flexible language, php converts data type of a variable based on your command, you can compare string against boolean or boolean against int php automatically figure what you really want to do at runtime. and it is also multi paradigm. you can choose to write pure OOP code or procedural
Re: Sorting Out A Simple Text Dictionary With PHP by dhtmlextreme(m): 3:53pm On Jul 24, 2014
^^^that is a PHP expert speaking and talking
Re: Sorting Out A Simple Text Dictionary With PHP by asalimpo(m): 3:43pm On Jul 25, 2014
cyrielo:
PHP is a dynamic and a flexible language, php converts data type of a variable based on your command, you can compare string against boolean or boolean against int php automatically figure what you really want to do at runtime. and it is also multi paradigm. you can choose to write pure OOP code or procedural

the point you miss dear sir,is tht standardzation is a necessary evil.
Mainstream programmg languages and software engineerg needs some form of standardzation, but standardzation usually stiffles innovation especially wen (as is often) the case an inferior technology gets standardzed.
E.g in d days of video cassetes, vhs was d standard,though,betamax was technologically superior.
In electrcity, DC, was d heavily touted standard but AC was better for electricity distribution. It took a lot of bitter fightg for AC to b adopted. Today, AC ,is used to get d power to ur house where it is stepped down to DC for ur electroncs to use.
Light bulbs are built to a standard so tht u dnt care who d manufacturer is,u just use it outta d box to replace a dead bulb,
usb interface has replaced former
serial ports for device to computer connectvty.
So watabout software?
In software its long being discovered ,painfully, tht multi paradigm without a controllg paradigm is detrimental.
C++ operated ths philosophy and d wrld is still hurtg so bad from it.
In c++, speed was d essense,
u cud do it in oop, structural,generically,or low level .
You cud mix up paradigms as u like-the result. complexity explosion, hard to track bugs, memory leaks tht cost corporations $1b annually (as at wen java was born). Yeah c++ was fast, but it was disastrous.
Lets not even talk about d perils of multiple inheritance and direct memory manipulation (wat language is d favrite for virus writers?)

Java (inspired by Ada) discarded the no-holds bared philosophy of c++ for a Big brother philosophy. No, you cant run code outside a class, here , put ur bags in d locker,
(variables in classes), and put d books in d bag (packages). The toilet seats go down after use (threadg). Evrythg goes in a class,
and every student must register with 3 names.. (lotsa a rules). It was too restrctve. But almost 20 yrs after, the rules of java and making oop d dominant paradigm controlling its other paradigms has sustained it this far.
Java now has 3 paradigms in it, oop,generic,and functional (as of java8).
Yet all paradigms are expressed thru oop.
Php has 2 paradigms oop,structural and it is repeatg the mistake c++ made.
Givg programmers license to mix as they please,enforcg no structure.
Result: it's so easy
(reminds you of javascript right?!).
Compare its contemporaries, ruby,python,clojure.
Ruby enforces one paradigm- oop
evrythg is an object.
Python enfrces one paradigm-oop
clojure enforces one paradigm- functional

one paradigm means one option for structurg code wich means greater modularity.
This is where php is failg. It has embraced oop but oop is just an add on. You can continue weavg more unstructred spaghetti wraps called code and pushg it to the server faster thn other more disciplined language practitioners can. But to d disciplined eye all he'll see is bad language design .
Re: Sorting Out A Simple Text Dictionary With PHP by cyrielo(m): 4:48pm On Jul 25, 2014
^^^^ if you want some standardization ever heard of Model View Controller (MVC) code design depends on the programmer not just the language! And yeah i could hack away one main java class and build full application in procedural style without creating any additional class tongue! well every language has its pros and cons. and what do you mean by c++ being disastrous please tell me more
Re: Sorting Out A Simple Text Dictionary With PHP by asalimpo(m): 2:03am On Jul 26, 2014
cyrielo: ^^^^ if you want some standardization ever heard of Model View Controller (MVC) code design depends on the programmer not just the language! And yeah i could hack away one main java class and build full application in procedural style without creating any additional class tongue! well every language has its pros and cons. and what do you mean by c++ being disastrous please tell me more
sure you could hack one big monolithic method - procedural style - in java. but you're still forced to conform to
the OOP paradigm. the method is in a class. and the class is the driver class.
no getting around it.
You can also create many unnecessary classes in the name of everything is an object mantra.
c++ is disastrous cuz c++ enforces no paradigm.
It assumes the dev knows what he's doing. because no paradigm is enforced, you can write structural code all the way, use global variables , go low level as you like. Some c coders crossing over to cpp , ditch the oop aspect of c++
and code in c++ completely in procedural style. No modularity. everything is just one procedure calling anoda procedure.
Messy code.
php follows in the footsteps of c++.

(1) (Reply)

Php Challenge: External Authentication Of Phpbb3 / Microsoft Ports. NET To Linux And Macintosh, Goes Open-sources; Is Java Doomed? / Android App Developers Charges

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 75
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.