├── .gitignore
├── .idea
├── .gitignore
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── mysam-tagmanager.iml
└── vcs.xml
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── README.rst
├── doc
├── images
│ ├── mysam_demo.png
│ └── mysam_sample.png
└── tagset.md
├── epydoc.conf
├── mysam
├── __init__.py
├── config
│ └── tag.config
├── tag_const.py
├── tag_const_inflect.py
├── tagcoder.py
├── tagconfig.py
├── taginflector.py
└── tagmaker.py
├── requirements
├── setup.py
└── tests
├── fixtures
└── tagcode_dataset.py
├── makedoc.py
├── readme_samples1.py
├── readme_samples2.py
├── readme_samples3.py
├── readme_samples4.py
├── readme_samples5.py
├── requirements
├── tag.config
├── test_config.py
├── test_maker.py
├── test_maker_readingtags.py
├── test_mytager.py
├── test_samples.py
└── test_unit_tagcoder.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | doc/html/*
3 | /doc/tagset.md.bak
4 | tests/output/*
5 | tests/samples/*
6 | build/*
7 | dist/*
8 | mysam_tagmanager.egg-info/*
9 | mypythonenv/
10 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/mysam-tagmanager.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include mysam/config/tag.config
2 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #/usr/bin/sh
2 | # Build mysam-tagmanager
3 |
4 | default: all
5 | # Clean build files
6 | clean:
7 |
8 | backup:
9 |
10 | #create all files
11 | all:
12 |
13 | install:
14 | sudo python setup.py install
15 | install3:
16 | sudo python3 setup.py install
17 | # Publish to github
18 | publish:
19 | git push origin master
20 |
21 | md2rst:
22 | pandoc -s -r markdown -w rst README.md -o README.rst
23 | md2html:
24 | pandoc -s -r markdown -w html README.md -o README.html
25 |
26 | wheel:
27 | sudo python3 setup.py bdist_wheel
28 | wheel3:
29 | sudo python3 setup.py bdist_wheel
30 | sdist:
31 | sudo python3 setup.py sdist
32 | upload:
33 | echo "use twine upload dist/mysam-tagmanager-0.1.tar.gz"
34 |
35 | test:
36 | cd tests; python3 test_maker.py
37 | test_unit:
38 | cd tests; python3 -m pytest test_unit_tagcoder.py
39 | tagsetdoc:
40 | mv doc/tagset.md doc/tagset.md.bak
41 | python3 tests/makedoc.py > doc/tagset.md
42 | doc:
43 | epydoc -v --config epydoc.conf
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Mysam: Arabic tags manager, ميسم: إدارة الوسوم العربية
2 |
3 | تسيير وسوم الكلمات العربية في مجال المعالجة الآلية للغة، ترميز وتفكيك
4 | هذه المكتبة توفر سكريبت خاصا بترميز وسوم الكلمات (الخصائص الصرفية والنحوية والدلالية) في عبارة وسم مختصرة على شكل سلسلة حروف قصيرة مرمّزة نسميها سلسلة الوسوم.
5 | يمكن التحويل بين قائمة الوسوم وسلسة الوسوم المختص
6 | يمكن الاستفادة من هذه المكتبة من أجل ترميز الوسوم وفك ترميزها، سنستعملها في :
7 |
8 | * التحليل الصرفي ([مكتبة قلصادي](https://github.com/linuxscout/qalsadi) )
9 | * التحليل النحوي ( [مكتبة ثعلب](https://github.com/linuxscout/thaalab-aranasyn) )
10 | * التشكيل ( برنامج مشكال[برنامج مشكال](https://github.com/linuxscout/mishkal) [ برنامج مشكال](http://tahadz.com/mishkal) )
11 | * التدقيق اللغوي النحوي (LanguageTool).
12 |
13 | كما تقدّم خدمة متميزة في **الإعراب بالطريقة القديمة **
14 |
15 | 
16 |
17 | * قائمة الوسوم :
18 | Noun, جامد, مضاف, مجرور, متحرك, ينون
19 | * سلسلة الوسوم المختصرة
20 | [N--;--I-;---H;----]
21 | * جملة الإعراب
22 | {اسم مجرور وهو مضاف، والضمير المتصل مبني في محل جر مضاف إليه}
23 |
24 | ** هذه ليست مكتبة للتوسيم، بل لإدارة الوسوم في معالجة اللغة**
25 |
26 |
27 | Manage arabic words tags, encode, decode
28 | This library provides a script to encode POS tags (Words features : morphology, syntax, semantic), as a brief tag string called tag string.
29 | We can convert between tag list <==> coded tag string.
30 | We plan to use it in:
31 |
32 | * Morphology analysis ([Qalsadi library](https://github.com/linuxscout/qalsadi) )
33 | * Syntactic analysis ( [Thaalab Library](https://github.com/linuxscout/thaalab-aranasyn) )
34 | * Tashkeel ( [Mishkal](https://github.com/linuxscout/mishkal) [Mishkal-site](http://tahadz.com/mishkal) )
35 | * LanguageTool - Style and Grammar Checker [LanguageTool](https://languagetool.org/).
36 |
37 | It provides a special feature, make **traditional Inflection**.
38 |
39 | The conversion can be do like:
40 |
41 | * Tags list:
42 | Noun, جامد, مضاف, مجرور, متحرك, ينون
43 | * Encoded tag string
44 | [N--;--I-;---H;----]
45 | * Inflection phrase
46 | {اسم مجرور وهو مضاف، والضمير المتصل مبني في محل جر مضاف إليه}
47 |
48 | ** This not a Tagger library, but, a tags mangger for NLP **
49 |
50 |
51 | ### Tagging System description
52 | You can look at tagging descripton on [doc/tagset.md](doc/tagset.md)
53 |
54 |
55 | Developpers: Taha Zerrouki: http://tahadz.com
56 | taha dot zerrouki at gmail dot com
57 |
58 | Features | value
59 | ------------|-----------
60 | Authors | Taha Zerrouki: http://tahadz.com, taha dot zerrouki at gmail dot com
61 | Release | 0.4
62 | License |[GPL](https://github.com/linuxscout/mysam-tagmanager/master/LICENSE)
63 | Tracker |[linuxscout/mysam-tagmanager/Issues](https://github.com/linuxscout/mysam-tagmanager/issues)
64 | Website |[https://pypi.python.org/pypi/mysam-tagmanager](https://pypi.python.org/pypi/mysam-tagmanager)
65 | Source |[Github](http://github.com/linuxscout/mysam-tagmanager)
66 | Feedbacks |[Comments](https://github.com/linuxscout/mysam-tagmanager/issues)
67 | Accounts |[@Twitter](https://twitter.com/linuxscout) [@Sourceforge](http://sourceforge.net/projects/mysam-tagmanager/)
68 |
69 |
70 |
71 |
72 | ## Citation
73 | If you would cite it in academic work, can you use this citation
74 | ```
75 | T. Zerrouki, mysam-tagmanager, Arabic Word Tagger,
76 | https://pypi.python.org/pypi/mysam-tagmanager/, 2018
77 | ```
78 | or in bibtex format
79 |
80 | ```bibtex
81 | @misc{zerrouki2018mysam,
82 | title={mysam-tagmanager : Arabic Word Tagger},
83 | author={Zerrouki, Taha},
84 | url={https://pypi.python.org/pypi/mysam-tagmanager,
85 | year={2018}
86 | }
87 | ```
88 |
89 |
90 | ## مزايا
91 | * ترميز المزايا إلى وسم موحد مختصر
92 | * تفكيك الوسم إلى خصائصه
93 | * توليد الإعراب حسب الطريق التقليدية
94 |
95 | ## Features
96 | * Encode features to an unified tag string
97 | * Encode unified tag string to a list of features
98 | * Generate a traditional inflection style
99 |
100 | ## Applications
101 | * Text summarizing.
102 | * Sentences identification.
103 | * Grammar analysis.
104 | * Morphological analysis.
105 |
106 | ## تطبيقات
107 | * التنقيب عن المعلومات.
108 | * التعرف على الجمل.
109 | * التحليل النحوي.
110 | * تسريع التحليل الصرفي.
111 |
112 |
113 |
114 | ## Demo جرّب
115 |
116 | يمكن التجربة على [موقع مشكال](http://tahadz.com/mishkal)
117 | ، اختر تشكيل، ثم مرّر الفأرة على الكلمة لرؤية التلميح
118 |
119 | You can test it on [Mishkal Site](http://tahadz.com/mishkal), choose: Tashkeel, and move mouse over word to get hint.
120 |
121 | 
122 |
123 | Installation
124 | =====
125 | ```python
126 | pip install mysam-tagmanager
127 | ```
128 | ## Usage
129 |
130 | ```python
131 | import mysam.tagmaker as tagmaker
132 | ```
133 | ## Example
134 |
135 | ### Test load configuration
136 |
137 | ```python
138 | import pandas as pd
139 |
140 | import mysam.tagconfig as tagconfig
141 | import mysam.tag_const as tag_const
142 |
143 | configuer = tagconfig.tagConfig()
144 | configuer.load_config()
145 | # display
146 | df = pd.DataFrame(configuer.tagsdict)
147 | print('****tagdict ****')
148 | print(df)
149 | *****Result *****
150 | ****tagdict ****
151 | اسم Noun فعل Verb أداة ... 1st person مخاطب 2nd person غائب 3rd person
152 | part 1 1 1 1 1 ... 4 4 4 4 4
153 | pos 1 1 1 1 1 ... 4 4 4 4 4
154 | attr word_type word_type word_type word_type word_type ... person person person person person
155 | ar_attr نوع الكلمة نوع الكلمة نوع الكلمة نوع الكلمة نوع الكلمة ... شخص شخص شخص شخص شخص
156 | code n n V V T ... I Y Y H H
157 | value Noun Noun Verb Verb Tool ... 1st person 2nd person 2nd person 3rd person 3rd person
158 | ar_value اسم اسم فعل فعل أداة ... متكلم مخاطب مخاطب غائب غائب
159 | inflect اسم اسم فعل فعل حرف ...
160 |
161 | [8 rows x 95 columns]
162 | ....
163 | ....
164 |
165 | ```
166 | You can load a specific config file by passing parameter to load_conf.
167 | If the file doesn't exist or failed to be open, the default config is loaded.
168 |
169 | ```python
170 | configuer = tagconfig.tagConfig()
171 | configuer.load_config("tag.config")
172 |
173 | ```
174 | If you want to know if the input file is opened, fix 'debug' parameter to 'True'
175 |
176 |
177 | If you want to know if the input file is open, fix 'debug' parameter to 'True'
178 | ```python
179 | configuer = tagconfig.tagConfig()
180 | configuer.load_config("tag.config", debug=True)
181 | ```
182 |
183 | ### Test call tagmaker
184 |
185 | ```python
186 | import mysam.tagcoder
187 | # given tags as list
188 | taglists = [[u'اسم', u'هاء', u'مجرور',],
189 | u'تعريف::مرفوع:متحرك:ينون:::'.split(":"),
190 | ]
191 | tgcoder = mysam.tagcoder.tagCoder()
192 | for taglist in taglists:
193 | # encode
194 | tagcode = tgcoder.encode(taglist)
195 | print("tags list:", u";".join(taglist))
196 | print("tagcode:", tagcode)
197 | # decode a tag code string into (key, values)
198 | print("decode:", tgcoder.decode(tagcode))
199 |
200 | **** result ****
201 | tags list: اسم;هاء;مجرور
202 | tagcode: N--;------I;---
203 | decode: [('نوع الكلمة', 'اسم'), ('خاصية', 'لاشيء'), ('جنس', 'لاشيء'), ('عدد', 'لاشيء'), ('شخص', 'لاشيء'), ('علامة', 'لاشيء'), ('زمن', 'لاشيء'), ('بناء', 'لاشيء'), ('إعراب', 'مجرور'), ('عطف', 'لاشيء'), ('استقبال', 'لاشيء'), ('ضمير متصل', 'لاشيء')]
204 | tags list: تعريف;;مرفوع;متحرك;ينون;;;
205 | tagcode: ---;------U;--L
206 | decode: [('نوع الكلمة', 'لاشيء'), ('خاصية', 'لاشيء'), ('جنس', 'لاشيء'), ('عدد', 'لاشيء'), ('شخص', 'لاشيء'), ('علامة', 'لاشيء'), ('زمن', 'لاشيء'), ('بناء', 'لاشيء'), ('إعراب', 'مرفوع'), ('عطف', 'لاشيء'), ('استقبال', 'لاشيء'), ('تعريف', 'معرفة')]
207 |
208 | ```
209 |
210 |
211 | ### Exmaple for inflect
212 | ```python
213 | import mysam.taginflector
214 | tag_maker = mysam.taginflector.tagInflector()
215 | word = "يَسْتَعْمِلُونَهَا"
216 | tagcode = 'V-1;M3H-faU;W-H'
217 | print(tag_maker.inflect(tagcode))
218 | **** result ****
219 | فعل مضارع مرفوع وعلامة رفعه ثبوت النون لأنه من الأفعال الخمسة والواو: ضمير متصل مبني في محل رفع فاعل والضمير المتصل مبني في محل نصب مفعول به
220 | ```
221 |
222 | ### Exmaple for add tag
223 |
224 | Add a new tag to existing tags string code
225 |
226 | ```python
227 | import mysam.tagcoder
228 | tag_coder = mysam.tagcoder.tagCoder()
229 | tagcode = 'V-0;M1H-faU;W--'
230 | tag = "ضمير متصل"
231 | print(tag_coder.add_tag(tag, tagcode))
232 | **** result ****
233 | V-0;M1H-faU;W-H
234 | ```
235 |
236 | ### Exmaple for remove tag
237 |
238 | Remove and a tag from existing tags string code
239 |
240 | ```python
241 | import mysam.tagcoder
242 | tag_coder = mysam.tagcoder.tagCoder()
243 | tagcode = 'V-0;M1H-faU;W-H'
244 | tag = "ضمير متصل"
245 | print(tag_coder.remove_tag(tag, tagcode))
246 | **** result ****
247 | V-0;M1H-faU;W--
248 | ```
249 |
250 | ###
251 |
252 | ### Exmaple for has tag
253 |
254 | ```python
255 | import mysam.tagcoder
256 | tag_coder = mysam.tagcoder.tagCoder()
257 | tags = ['اسم', 'مجرور', 'مذكر', "مفرد", "واو"]
258 | tagcode = tag_coder.encode(tags)
259 | print(tagcode)
260 | tag_search = u"مجرور"
261 | print(tag_coder.has_tag(tag_search, tagcode))
262 | tag_search = u"فعل"
263 | print(tag_coder.has_tag(tag_search, tagcode))
264 | **** result ****
265 | N--;M1----I;---
266 | True
267 | False
268 | ```
269 |
270 |
271 |
272 |
273 |
274 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | Mysam: Arabic tags manager, ميسم: إدارة الوسوم العربية
2 | ======================================================
3 |
4 | تسيير وسوم الكلمات العربية في مجال المعالجة الآلية للغة، ترميز وتفكيك
5 | هذه المكتبة توفر سكريبتا خاصا بترميز وسوم الكلمات (الخصائص الصرفية
6 | والنحوية والدلالية) في عبارة وسم مختصرة على شكل سلسلة حروف قصيرة مرمّزة
7 | نسميها سلسلة الوسوم. يمكن التحويل بين قائمة الوسوم وسلسة الوسوم المختص
8 | يمكن الاستفادة من هذه المكتبة من أجل ترميز الوسوم وفك ترميزها، سنستعملها
9 | في :
10 |
11 | - التحليل الصرفي (`مكتبة
12 | قلصادي `__ )
13 | - التحليل النحوي ( `مكتبة
14 | ثعلب `__ )
15 | - التشكيل ( برنامج مشكال\ `برنامج
16 | مشكال `__ `برنامج
17 | مشكال `__ )
18 | - التدقيق اللغوي النحوي (LanguageTool).
19 |
20 |
21 | كما تقدّم خدمة متميزة في الإعراب بالطريقة القديمة
22 |
23 |
24 |
25 |
26 | - قائمة الوسوم : Noun, جامد, مضاف, مجرور, متحرك, ينون
27 | - سلسلة الوسوم المختصرة [N--;--I-;---H;----]
28 | - جملة الإعراب {اسم مجرور وهو مضاف، والضمير المتصل مبني في محل جر مضاف
29 | إليه}
30 |
31 | \*\* هذه ليست مكتبة للتوسيم، بل لإدارة الوسوم في معالجة اللغة\*\*
32 |
33 | Manage arabic words tags, encode, decode This library provides a script
34 | to encode POS tags (Words features : morphology, syntax, semantic), as a
35 | brief tag string called tag string. We can convert between tag list <==>
36 | coded tag string. We plan to use it in:
37 |
38 | - Morphology analysis (`Qalsadi
39 | library `__ )
40 | - Syntactic analysis ( `Thaalab
41 | Library `__ )
42 | - Tashkeel ( `Mishkal `__
43 | `Mishkal-site `__ )
44 | - LanguageTool - Style and Grammar Checker
45 | `LanguageTool `__.
46 |
47 | It provides a special feature, make **traditional Inflection**.
48 |
49 | The conversion can be do like:
50 |
51 | - Tags list: Noun, جامد, مضاف, مجرور, متحرك, ينون
52 | - Encoded tag string [N--;--I-;---H;----]
53 | - Inflection phrase {اسم مجرور وهو مضاف، والضمير المتصل مبني في محل جر
54 | مضاف إليه}
55 |
56 | \*\* This not a Tagger library, but, a tags mangger for NLP \*\*
57 |
58 | Tagging System description
59 | --------------------------
60 |
61 | You can look at tagging descripton on `doc/tagset.md `__
62 |
63 | Developpers: Taha Zerrouki: http://tahadz.com taha dot zerrouki at gmail
64 | dot com
65 |
66 | +---------------+--------------+
67 | | Features | value |
68 | +===============+==============+
69 | | Authors | Taha |
70 | | | Zerrouki: |
71 | | | http://tahad |
72 | | | z.com, |
73 | | | taha dot |
74 | | | zerrouki at |
75 | | | gmail dot |
76 | | | com |
77 | +---------------+--------------+
78 | | Release | 0.2 |
79 | +---------------+--------------+
80 | | License | `GPL `__ |
86 | +---------------+--------------+
87 | | Tracker | `linuxscout/ |
88 | | | mysam-tagman |
89 | | | ager/Issues |
90 | | | `__ |
95 | +---------------+--------------+
96 | | Website | https://pypi |
97 | | | .python.org/ |
98 | | | pypi/mysam-t |
99 | | | agmanager |
100 | +---------------+--------------+
101 | | Source | `Github `__ |
106 | +---------------+--------------+
107 | | Feedbacks | `Comments `__ |
113 | +---------------+--------------+
114 | | Accounts | [@Twitter](h |
115 | | | ttps://twitt |
116 | | | er.com/linux |
117 | | | scout) |
118 | | | [@Sourceforg |
119 | | | e](http://so |
120 | | | urceforge.ne |
121 | | | t/projects/m |
122 | | | ysam-tagmana |
123 | | | ger/) |
124 | +---------------+--------------+
125 |
126 |
127 |
128 | مزايا
129 | -----
130 |
131 | - ترميز المزايا إلى وسم موحد مختصر
132 | - تفكيك الوسم إلى خصائصه
133 | - توليد الإعراب حسب الطريق التقليدية
134 |
135 | Features
136 | --------
137 |
138 | - Encode features to an unified tag string
139 | - Encode unified tag string to a list of features
140 | - Generate a traditional inflection style
141 |
142 | Applications
143 | ------------
144 |
145 | - Text summarizing.
146 | - Sentences identification.
147 | - Grammar analysis.
148 | - Morphological analysis.
149 |
150 | تطبيقات
151 | -------
152 |
153 | - التنقيب عن المعلومات.
154 | - التعرف على الجمل.
155 | - التحليل النحوي.
156 | - تسريع التحليل الصرفي.
157 |
158 | Demo جرّب
159 | ---------
160 |
161 | يمكن التجربة على `موقع مشكال `__ ، اختر
162 | تشكيل، ثم مرّر الفأرة على الكلمة لرؤية التلميح
163 |
164 | You can test it on `Mishkal Site `__, choose:
165 | Tashkeel, and move mouse over word to get hint.
166 |
167 |
168 |
169 |
170 | Installation
171 | ============
172 | ```
173 | pip install mysam-tagmanager
174 | ```
175 |
176 |
177 | Usage
178 | -----
179 |
180 | .. code:: python
181 |
182 | import mysam.tagmaker as tagmaker
183 |
184 | Example
185 | -------
186 |
187 | Test load configuration
188 | ~~~~~~~~~~~~~~~~~~~~~~~
189 |
190 | .. code:: python
191 |
192 | import mysam.tagconfig as tagconfig
193 | import mysam.tag_const as tag_const
194 | import pandas as pd
195 | configuer = tagconfig.tagConfig()
196 | configuer.load_config()
197 | # display
198 | df = pd.DataFrame(tag_const.TAGSDICT)
199 | print('****tagdict ****')
200 | print(df)
201 | *****Result *****
202 | ****tagdict ****
203 | 1st person 2nd person 3rd person Beh FEH \
204 | ar_attr شخص شخص شخص جر عطف
205 | ar_value متكلم مخاطب غائب باء الفاء
206 | attr person person person preposition conjonction
207 | code I Y H B F
208 | inflect بالباء
209 | part 4 4 4 3 3
210 | pos 4 4 4 2 1
211 | value 1st person 2nd person 3rd person Beh FEH
212 | ....
213 | ....
214 |
215 | You can load a specific config file by passing parameter to load\_conf.
216 | If the file doesn't exist or failed to be open, the default config is
217 | loaded.
218 |
219 | .. code:: python
220 |
221 | configuer = tagconfig.tagConfig()
222 | configuer.load_config("tag.config")
223 |
224 | If you want to know if the input file is opened, fix 'debug' parameter
225 | to 'True'
226 |
227 | If you want to know if the input file is open, fix 'debug' parameter to
228 | 'True'
229 |
230 | .. code:: python
231 |
232 | configuer = tagconfig.tagConfig()
233 | configuer.load_config("tag.config", debug=True)
234 |
235 | Test call tagmaker
236 | ~~~~~~~~~~~~~~~~~~
237 |
238 | .. code:: python
239 |
240 | import mysam.tagmaker as tagmaker
241 |
242 | taglists = [[u'اسم', u'هاء', u'مجرور',],
243 | u'تعريف::مرفوع:متحرك:ينون:::'.split(":"),
244 | ]
245 | for taglist in taglists:
246 | tag_maker = tagmaker.tagMaker()
247 | # encode
248 | tag_maker.encode(taglist)
249 | print(u"+".join(taglist).encode('utf8'))
250 | tagstr = str(tag_maker)
251 | print(tagstr)
252 | # decode a unifed tag string
253 | print(tag_maker.decode())
254 |
255 | **** result ****
256 |
257 | اسم+هاء+مجرور
258 | N--;--I-;----;----
259 | [(u'نوع الكلمة', u'اسم'), (u'جنس', u'لاشيء'), (u'عدد', u'لاشيء'), (u'إعراب', u'مجرور'), (u'علامة', u'لاشيء'), (u'عطف', u'لاشيء'), (u'جر', u'لاشيء'), (u'تعريف', u'نكرة'), (u'ضمير متصل', u'لاشيء'), (u'استقبال', u'لاشيء'), (u'بناء', u'لاشيء'), (u'زمن', u'لاشيء'), (u'شخص', u'لاشيء')]
260 | تعريف++مرفوع+متحرك+ينون+++
261 | ---;--U-;--L-;----
262 | [(u'نوع الكلمة', u'لاشيء'), (u'جنس', u'لاشيء'), (u'عدد', u'لاشيء'), (u'إعراب', u'مرفوع'), (u'علامة', u'لاشيء'), (u'عطف', u'لاشيء'), (u'جر', u'لاشيء'), (u'تعريف', u'معرفة'), (u'ضمير متصل', u'لاشيء'), (u'استقبال', u'لاشيء'), (u'بناء', u'لاشيء'), (u'زمن', u'لاشيء'), (u'شخص', u'لاشيء')]
263 |
264 |
265 | Exmaple for inflect
266 | ~~~~~~~~~~~~~~~~~~~
267 |
268 | .. code:: python
269 |
270 | >>> tag_maker = tagmaker.tagMaker()
271 | >>> tagcode = 'N--;--I-;----;---'
272 | >>> print(tag_maker.inflect(tagcode).encode('utf8'))
273 | اسم مجرور وعلامة جرّه الياء لأنه جمع مذكر سالم وهو مضاف، والضمير المتصل مبني في محل جر مضاف إليه
274 |
275 | Exmaple for add tag
276 | ~~~~~~~~~~~~~~~~~~~
277 |
278 | .. code:: python
279 |
280 | >>> tag_maker = tagmaker.tagMaker()
281 | >>> tagcode = 'N--;--I-;----;---'
282 | >>> tag_new = u"تعريف"
283 | >>> tag_maker.add(tag_new)
284 | >>> tag_new = u"اسم"
285 | >>> tag_maker.add(tag_new)
286 | >>> print(str(tag_maker).encode('utf8'))
287 | N--;----;--L-;----
288 |
289 | Exmaple for has tag
290 | ~~~~~~~~~~~~~~~~~~~
291 |
292 | .. code:: python
293 |
294 | >>> tag_maker = tagmaker.tagMaker()
295 | >>> tagcode = 'N--;--I-;----;---'
296 | >>> tag_search = u"مجرور"
297 | >>> print(tag_maker.has_tag(tag_search, tagcode))
298 | True
299 |
--------------------------------------------------------------------------------
/doc/images/mysam_demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linuxscout/mysam-tagmanager/9fb18f7919391c8f3ac4e94c2add68b119195edc/doc/images/mysam_demo.png
--------------------------------------------------------------------------------
/doc/images/mysam_sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linuxscout/mysam-tagmanager/9fb18f7919391c8f3ac4e94c2add68b119195edc/doc/images/mysam_sample.png
--------------------------------------------------------------------------------
/doc/tagset.md:
--------------------------------------------------------------------------------
1 | # Description
2 | ## Structure
3 | TAG_PARTS_SIZES=[[3, 4, 5, 5]]
4 | TAG_PARTS_SEP =';'
5 | Structure =[---;----;-----;-----]
6 | ## Parts
7 | Word Type نوع الكلمة
8 | Sub Class صنف فرعي
9 | transitive
10 | Conjugation
11 | Gender الجنس
12 | Number العدد
13 | Inlfection case الحالة الإعرابية
14 | Inflection marks
15 | Procletics and prefixes
16 | Conjuction
17 | preposition
18 | Definition
19 | Enclitics
20 | Special Verb
21 | Istiqbal
22 | Voice البناء
23 | tense الزمن
24 | person الشخص
25 | Parameters: must starts by #PARAM:
26 | ## Detailled
27 | ## Word Type نوع الكلمة:
28 |
29 | N: Noun
30 | V: Verb
31 | T: Tool
32 | P: Punctuation
33 | S: Symbol
34 | D: Numeric
35 | -: Undef
36 | Sub Class صنف فرعي:
37 | M: Masdar
38 | transitive:
39 | 0: intransitive
40 | 1: transitive
41 | 2: double transitive
42 | 4: commun
43 | تعدي: undef
44 | ## Conjugation:
45 |
46 | Gender الجنس:
47 | M: masculine
48 | F: Feminine
49 | -: none
50 | Number العدد:
51 | 1: single
52 | 2: dual
53 | 3: plural
54 | 4: plural
55 | -: none
56 | Inlfection case الحالة الإعرابية:
57 | U: marfou3
58 | 0: manjzoum
59 | I: majrour
60 | A: mansoub
61 | B: mabni
62 | -: undef
63 | Inflection marks:
64 | u: damma
65 | a: fatha
66 | i: kasra
67 | 0: sukun
68 | A: alef
69 | W: waw
70 | Y: yeh
71 | N: noon
72 | -: undef
73 | ## Procletics and prefixes:
74 |
75 | Conjuction:
76 | W: WAW
77 | F: FEH
78 | -: undef
79 | preposition:
80 | B: Beh
81 | K: Kaf
82 | L: Lam
83 | -: undef
84 | Definition:
85 | L: definited
86 | -: indefinite
87 | Enclitics:
88 | H: Heh
89 | -: undef
90 | ## Special Verb:
91 |
92 | Istiqbal:
93 | s: istqbal
94 | -: undef
95 | Voice البناء:
96 | a: acive voice
97 | p: acive voice
98 | -: undef
99 | tense الزمن:
100 | p: past
101 | f: present
102 | i: imperative
103 | -: undef
104 | person الشخص:
105 | I: 1st person
106 | Y: 2nd person
107 | H: 3rd person
108 | -: undef
109 | ##Parameters: must starts by #PARAM::
110 |
111 | # Table of configuration
112 | ## Columns description
113 | * #Part
114 | * Pos
115 | * Attribute
116 | * خاصية
117 | * code
118 | * Value
119 | * قيمة
120 | * inflection
121 | *
122 |
123 |
124 | ## Word Type نوع الكلمة
125 |
126 |
127 | #Part|Pos|Attribute|خاصية|code|Value|قيمة|inflection|
128 | -----|---|---------|-----|----|-----|----|----------|
129 | 1|1|word_type|نوع الكلمة|N|Noun|اسم|اسم|
130 | 1|1|word_type|نوع الكلمة|V|Verb|فعل|فعل|
131 | 1|1|word_type|نوع الكلمة|T|Tool|أداة|حرف|
132 | 1|1|word_type|نوع الكلمة|P|Punctuation|ترقيم|علامة ترقيم|
133 | 1|1|word_type|نوع الكلمة|S|Symbol|رمز|رمز|
134 | 1|1|word_type|نوع الكلمة|D|Numeric|عدد|عدد|
135 | 1|1|word_type|نوع الكلمة|-|Undef|لاشيء||
136 | 1|2|subclass|صنف|M|Masdar|مصدر||
137 | 1|3|transitive|تعدي|0|intransitive|لازم||
138 | 1|3|transitive|تعدي|1|transitive|متعدي||
139 | 1|3|transitive|تعدي|2|double transitive|متعدي لمفعولين||
140 | 1|3|transitive|تعدي|4|commun|مشترك||
141 | 1|3|transitive|-|تعدي|undef|لاشيء||
142 |
143 |
144 | ## Conjugation
145 |
146 |
147 | #Part|Pos|Attribute|خاصية|code|Value|قيمة|inflection|
148 | -----|---|---------|-----|----|-----|----|----------|
149 | 2|1|gender|جنس|M|masculine|مذكر|مذكر
150 | 2|1|gender|جنس|F|Feminine|مؤنث|مؤنث|
151 | 2|1|gender|جنس|-|none|لاشيء||
152 | 2|2|number|عدد|1|single|مفرد|مفرد|
153 | 2|2|number|عدد|2|dual|مثنى|مثنى|
154 | 2|2|number|عدد|3|plural|جمع|جمع|
155 | 2|2|number|عدد|4|plural|جمع تكسير|جمع تكسير|
156 | 2|2|number|عدد|-|none|لاشيء||
157 | 2|3|case|إعراب|U|marfou3|مرفوع|مرفوع|
158 | 2|3|case|إعراب|0|manjzoum| مجزوم|مجزوم|
159 | 2|3|case|إعراب|I|majrour|مجرور|مجرور|
160 | 2|3|case|إعراب|A|mansoub|منصوب|منصوب|
161 | 2|3|case|إعراب|B|mabni|مبني|مبني|
162 | 2|3|case|إعراب|-|undef|لاشيء||
163 | 2|4|mark|علامة|u|damma|الضمة|الضمة|
164 | 2|4|mark|علامة|a|fatha|الفتحة|الفتحة|
165 | 2|4|mark|علامة|i|kasra|الكسرة|الكسرة|
166 | 2|4|mark|علامة|0|sukun|السكون|السكون|
167 | 2|4|mark|علامة|A|alef|الألف|الألف|
168 | 2|4|mark|علامة|W|waw|الواو|الواو|
169 | 2|4|mark|علامة|Y|yeh|الياء|الياء|
170 | 2|4|mark|علامة|N|noon|ثبوت النون|ثبوت النون|
171 | 2|4|mark|علامة|-|undef|لاشيء||
172 |
173 |
174 | ## Procletics and prefixes
175 |
176 |
177 | #Part|Pos|Attribute|خاصية|code|Value|قيمة|inflection|
178 | -----|---|---------|-----|----|-----|----|----------|
179 | 3|1|conjonction|عطف|W|WAW|الواو||
180 | 3|1|conjonction|عطف|F|FEH|الفاء||
181 | 3|1|conjonction|عطف|-|undef|لاشيء||
182 | 3|2|preposition|جر|B|Beh|باء|بالباء|
183 | 3|2|preposition|جر|K|Kaf|كاف|بالكاف|
184 | 3|2|preposition|جر|L|Lam|لام|باللام|
185 | 3|2|preposition|جر|-|undef|لاشيء||
186 | 3|3|definite|تعريف|L|definited|معرفة||
187 | 3|3|definite|تعريف|-|indefinite|نكرة||
188 | 3|4|encletic|ضمير متصل|H|Heh|ضمير متصل|والضمير المتصل مبني|
189 | 3|4|encletic|ضمير متصل|-|undef|لاشيء||
190 |
191 |
192 | ## Special Verb
193 |
194 |
195 | #Part|Pos|Attribute|خاصية|code|Value|قيمة|inflection|
196 | -----|---|---------|-----|----|-----|----|----------|
197 | 4|1|istqbal|استقبال|s|istqbal|استقبال|استقبال|
198 | 4|1|istqbal|استقبال|-|undef|لاشيء||
199 | 4|2|voice|بناء|a|acive voice|معلوم|مبني للمعلوم|
200 | 4|2|voice|بناء|p|acive voice|مجهول|مبني للمجهول|
201 | 4|2|voice|بناء|-|undef|لاشيء||
202 | 4|3|tense|زمن|p|past|ماض|ماضي|
203 | 4|3|tense|زمن|f|present|مضارع|مضارع|
204 | 4|3|tense|زمن|i|imperative|أمر|أمر|
205 | 4|3|tense|زمن|-|undef|لاشيء||
206 | 4|4|person|شخص|I|1st person|متكلم||
207 | 4|4|person|شخص|Y|2nd person|مخاطب||
208 | 4|4|person|شخص|H|3rd person|غائب||
209 | 4|4|person|شخص|-|undef|لاشيء||
210 |
211 |
212 | ##Parameters: must starts by #PARAM:
213 |
214 |
215 | # TAGS MAP
216 | Feature|maps
217 | -------|----
218 | الأمر المؤكد|أمر, مؤكذ
219 | الأمر|أمر
220 | المضارع المعلوم|مضارع, معلوم, مرفوع
221 | نحن|متكلم, جمع
222 | المضارع المجهول|مضارع, مجهول, مرفوع
223 | مضاف|ضمير متصل
224 | المضارع المنصوب|مضارع, معلوم, منصوب
225 | أنت|مخاطب, مذكر, مفرد
226 | أنا|متكلم, مفرد
227 | المضارع المؤكد الثقيل|مضارع, معلوم, مؤكد
228 | أنتما|مخاطب, مذكر, مثنى
229 | أنتما مؤ|مخاطب, مؤنث, مثنى
230 | Verb|فعل
231 | تعريف|معرفة
232 | المضارع المجزوم|مضارع, معلوم, مجزوم
233 | Noun|اسم
234 | الماضي المجهول|ماضي, مجهول
235 | هن|غائب, مؤنث, جمع
236 | هم|غائب, مذكر, جمع
237 | هما|غائب, مذكر, مثنى
238 | المضارع المجهول المنصوب|مضارع, مجهول, منصوب
239 | مفعول به|ضمير متصل
240 | هما مؤ|غائب, مؤنث, مثنى
241 | هي|غائب, مؤنث, مفرد
242 | المضارع المؤكد الثقيل المجهول |مضارع, مجهول, مؤكد
243 | هو|غائب, مذكر, مفرد
244 | أنتِ|مخاطب, مؤنث, مفرد
245 | الماضي المعلوم|ماضي, معلوم
246 | n|لازم
247 | المضارع المجهول المجزوم|مضارع, مجهول, مجزوم
248 | أنتم|مخاطب, مذكر, جمع
249 | أنتن|مخاطب, مؤنث, جمع
250 | y|متعدي
251 |
--------------------------------------------------------------------------------
/epydoc.conf:
--------------------------------------------------------------------------------
1 | [epydoc] # Epydoc section marker (required by ConfigParser)
2 |
3 | # Information about the project.
4 | name: Mysam: Arabic tags manager
5 | url: https://pypi.python.org/pypi/mysam-tagmanager/
6 |
7 | # The list of modules to document. Modules can be named using
8 | # dotted names, module filenames, or package directory names.
9 | # This option may be repeated.
10 | modules: mysam/tagconfig.py, mysam/tagmaker.py
11 |
12 | # Write html output to the directory "apidocs"
13 | output: html
14 | target: doc/html/
15 |
16 | # Include all automatically generated graphs. These graphs are
17 | # generated using Graphviz dot.
18 | graph: all
19 | dotpath: /usr/bin/dot
20 |
--------------------------------------------------------------------------------
/mysam/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/mysam/config/tag.config:
--------------------------------------------------------------------------------
1 | #Part;Pos;Attribute;خاصية;code;Value;قيمة;inflection;
2 | # Word Type نوع الكلمة
3 | 1;1;word_type;نوع الكلمة;N;Noun;اسم;اسم;
4 | 1;1;word_type;نوع الكلمة;V;Verb;فعل;فعل;
5 | 1;1;word_type;نوع الكلمة;T;Tool;أداة;حرف;
6 | 1;1;word_type;نوع الكلمة;P;Punctuation;ترقيم;علامة ترقيم;
7 | 1;1;word_type;نوع الكلمة;S;Symbol;رمز;رمز;
8 | 1;1;word_type;نوع الكلمة;D;Numeric;عدد;عدد;
9 | 1;1;word_type;نوع الكلمة;-;Undef;لاشيء;;
10 |
11 | ## Sub Class صنف فرعي
12 | 1;2;subclass;صنف;M;Masdar;مصدر;;
13 | 1;2;subclass;صنف;A;Adjective;صفة;;
14 | 1;2;subclass;صنف;A;Adjective similair;صفة مشبهة;;
15 | 1;2;subclass;صنف;A;Adjective superlative;صيغة مبالغة;;
16 | 1;2;subclass;صنف;A;maf3oul;اسم مفعول;;
17 | 1;2;subclass;صنف;A;fa3il;اسم فاعل;;
18 | 1;2;subclass;صنف;P;Proper Noun;اسم علم;;
19 | 1;2;subclass;صنف;S;Superlative;اسم تفضيل;;
20 | 1;2;subclass;صنف;J;jamid;جامد;;
21 | 1;2;subclass;صنف;N;invariable;فعل جامد;;
22 | 1;2;subclass;صنف;H;heart;أفعال القلوب;;
23 | 1;2;subclass;صنف;R;probability;أفعال الظن;;
24 | 1;2;subclass;صنف;T;Tranfert;أفعال التحويل;;
25 | 1;2;subclass;صنف;I;initiative;أفعال الشروع;;
26 | 1;2;subclass;صنف;W;Weak;معتل;معتل;
27 | 1;2;subclass;صنف;3;tri;ثلاثي;-;
28 | 1;2;subclass;صنف;4;quadri;رباعي;-;
29 | 1;2;subclass;صنف;5;quinti;خماسي;-;
30 | 1;2;subclass;صنف;6;hex;سداسي;-;
31 |
32 | ## noun options
33 | 1;3;option;خاصية;R;Related;منسوب;;
34 | 1;3;option;خاصية;-;none;لاشيء;;
35 |
36 | ## transitive
37 | 1;3;transitive;تعدي;0;intransitive;لازم;;
38 | 1;3;transitive;تعدي;1;transitive;متعدي;;
39 | 1;3;transitive;تعدي;2;double transitive;متعدي لمفعولين;;
40 | 1;3;transitive;تعدي;4;commun;مشترك;;
41 | 1;3;transitive;-;تعدي;undef;لاشيء;;
42 |
43 | # Conjugation
44 | ## Gender الجنس
45 | 2;1;gender;جنس;M;masculine;مذكر;مذكر
46 | 2;1;gender;جنس;F;Feminine;مؤنث;مؤنث;
47 | 2;1;gender;جنس;-;none;لاشيء;;
48 | ## Number العدد
49 | 2;2;number;عدد;1;single;مفرد;مفرد;
50 | 2;2;number;عدد;2;dual;مثنى;مثنى;
51 | 2;2;number;عدد;3;plural;جمع;جمع;
52 | 2;2;number;عدد;4;plural;جمع تكسير;جمع تكسير;
53 | 2;2;number;عدد;-;none;لاشيء;;
54 |
55 | ## person الشخص
56 | 2;3;person;شخص;I;1st person;متكلم;;
57 | 2;3;person;شخص;Y;2nd person;مخاطب;;
58 | 2;3;person;شخص;H;3rd person;غائب;;
59 | 2;3;person;شخص;-;undef;لاشيء;;
60 |
61 | ## Inflection marks
62 | 2;4;mark;علامة;u;damma;الضمة;الضمة;
63 | 2;4;mark;علامة;a;fatha;الفتحة;الفتحة;
64 | 2;4;mark;علامة;i;kasra;الكسرة;الكسرة;
65 | 2;4;mark;علامة;0;sukun;السكون;السكون;
66 | 2;4;mark;علامة;U;dammatan;تنوين الضمة;;
67 | 2;4;mark;علامة;e;fathatan;تنوين الفتحة;;
68 | 2;4;mark;علامة;E;alef_fathatan;تنوين الألف;;
69 | 2;4;mark;علامة;I;kasratan;تنوين الكسرة;;
70 | 2;4;mark;علامة;A;alef;الألف;الألف;
71 | 2;4;mark;علامة;W;waw;الواو;الواو;
72 | 2;4;mark;علامة;Y;yeh;الياء;الياء;
73 | 2;4;mark;علامة;N;noon;ثبوت النون;ثبوت النون;
74 | 2;4;mark;علامة;-;undef;لاشيء;;
75 | ## tense الزمن
76 | 2;5;tense;زمن;p;past;ماضي;ماضٍ;
77 | 2;5;tense;زمن;f;present;مضارع;مضارع;
78 | 2;5;tense;زمن;i;imperative;أمر;أمر;
79 | 2;5;tense;زمن;-;undef;لاشيء;;
80 |
81 | ## Voice البناء
82 | 2;6;voice;بناء;a;acive voice;معلوم;;
83 | 2;6;voice;بناء;p;acive voice;مجهول;مبني للمجهول;
84 | 2;6;voice;بناء;-;undef;لاشيء;;
85 |
86 |
87 |
88 | ## Inlfection case الحالة الإعرابية
89 | 2;7;case;إعراب;U;marfou3;مرفوع;مرفوع;
90 | 2;7;case;إعراب;0;manjzoum;مجزوم;مجزوم;
91 | 2;7;case;إعراب;I;majrour;مجرور;مجرور;
92 | 2;7;case;إعراب;A;mansoub;منصوب;منصوب;
93 | 2;7;case;إعراب;B;mabni;مبني;مبني;
94 | 2;7;case;إعراب;-;undef;لاشيء;;
95 | 2;7;case;إعراب;M;confirmed;مؤكد;مؤكد;
96 |
97 | # Procletics and prefixes
98 | ## Conjuction
99 | 3;1;conjonction;عطف;W;WAW;معطوف بالواو;الواو حرف عطف;
100 | 3;1;conjonction;عطف;F;FEH;معطوف بالفاء;الفاء حرف عطف;
101 | 3;1;conjonction;عطف;-;undef;لاشيء;;
102 | ## preposition
103 | 3;2;preposition;جر;B;Beh;مجرور بالباء;باء;
104 | 3;2;preposition;جر;K;Kaf;مجرور بالكاف;كاف;
105 | 3;2;preposition;جر;L;Lam;مجرور باللام;لام;
106 | 3;2;preposition;جر;-;undef;لاشيء;;
107 |
108 | # Special Verb
109 | ## Istiqbal
110 | 3;2;istqbal;استقبال;s;istqbal;استقبال;استقبال;
111 | 3;2;istqbal;استقبال;-;undef;لاشيء;;
112 |
113 | ## Definition for nouns
114 | 3;3;definite;تعريف;L;definited;معرفة;;
115 | 3;3;definite;تعريف;-;indefinite;نكرة;;
116 |
117 | ## Enclitics for verbs and nouns
118 | 3;3;encletic;ضمير متصل;H;Heh;ضمير متصل;والضمير المتصل مبني;
119 | 3;3;encletic;ضمير متصل;-;undef;لاشيء;;
120 |
121 |
122 | #Parameters: must starts by #PARAM:
123 | $PARAM:TAG_PARTS_SIZES=3;7;3
124 |
125 | $MAP:المضارع المعلوم=مضارع;معلوم;مرفوع
126 | $MAP:المضارع المجزوم=مضارع;معلوم;مجزوم
127 | $MAP:Noun=اسم
128 | $MAP:y=متعدي
129 | $MAP:الأمر المؤكد=أمر;مؤكد
130 | $MAP:مضاف=ضمير متصل
131 | $MAP:الأمر=أمر
132 | $MAP:هن=غائب;مؤنث;جمع
133 | $MAP:هم=غائب;مذكر;جمع
134 | $MAP:هما=غائب;مذكر;مثنى
135 | $MAP:المضارع المجهول المنصوب=مضارع;مجهول;منصوب
136 | $MAP:المضارع المجهول المجزوم=مضارع;مجهول;مجزوم
137 | $MAP:مفعول به=ضمير متصل
138 | $MAP:n=لازم
139 | $MAP:هما مؤ=غائب;مؤنث;مثنى
140 | $MAP:هي=غائب;مؤنث;مفرد
141 | $MAP:المضارع المؤكد الثقيل المجهول =مضارع;مجهول;مؤكد
142 | $MAP:هو=غائب;مذكر;مفرد
143 | $MAP:أنتِ=مخاطب;مؤنث;مفرد
144 | $MAP:المضارع المنصوب=مضارع;معلوم;منصوب
145 | $MAP:أنت=مخاطب;مذكر;مفرد
146 | $MAP:الماضي المجهول=ماضي;مجهول
147 | $MAP:أنا=متكلم;مذكر;مفرد
148 | $MAP:الماضي المعلوم=ماضي;معلوم
149 | $MAP:المضارع المؤكد الثقيل=مضارع;معلوم;مؤكد
150 | $MAP:أنتما مؤ=مخاطب;مؤنث;مثنى
151 | $MAP:المضارع المجهول=مضارع;مجهول;مرفوع
152 | $MAP:أنتما=مخاطب;مذكر;مثنى
153 | $MAP:Verb=فعل
154 | $MAP:أنتم=مخاطب;مذكر;جمع
155 | $MAP:تعريف=معرفة
156 | $MAP:أنتن=مخاطب;مؤنث;جمع
157 | $MAP:نحن=متكلم;مذكر;جمع
158 |
159 |
--------------------------------------------------------------------------------
/mysam/tag_const.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # tag_const.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import os
25 | CONFIG_FILE = os.path.join( os.path.dirname(__file__), "config/tag.config")
26 | # stucture
27 | TAGS_CONFIG=u"""#Part;Pos;Attribute;خاصية;code;Value;قيمة;inflection;
28 | # Word Type نوع الكلمة
29 | 1;1;word_type;نوع الكلمة;n;Noun;اسم;اسم;
30 | 1;1;word_type;نوع الكلمة;V;Verb;فعل;فعل;
31 | 1;1;word_type;نوع الكلمة;T;Tool;أداة;حرف;
32 | 1;1;word_type;نوع الكلمة;P;Punctuation;ترقيم;علامة ترقيم;
33 | 1;1;word_type;نوع الكلمة;S;Symbol;رمز;رمز;
34 | 1;1;word_type;نوع الكلمة;D;Numeric;عدد;عدد;
35 | 1;1;word_type;نوع الكلمة;-;Undef;لاشيء;;
36 | ## Sub Class صنف فرعي
37 | 1;2;subclass;صنف;M;Masdar;مصدر;;
38 | ## transitive
39 | 1;3;transitive;تعدي;0;intransitive;لازم;;
40 | 1;3;transitive;تعدي;1;transitive;متعدي;;
41 | 1;3;transitive;تعدي;2;double transitive;متعدي لمفعولين;;
42 | 1;3;transitive;تعدي;4;commun;مشترك;;
43 | 1;3;transitive;-;تعدي;undef;لاشيء;;
44 |
45 | # Conjugation
46 | ## Gender الجنس
47 | 2;1;gender;جنس;M;masculine;مذكر;مذكر
48 | 2;1;gender;جنس;F;Feminine;مؤنث;مؤنث;
49 | 2;1;gender;جنس;-;none;لاشيء;;
50 | ## Number العدد
51 | 2;2;number;عدد;1;single;مفرد;مفرد;
52 | 2;2;number;عدد;2;dual;مثنى;مثنى;
53 | 2;2;number;عدد;3;plural;جمع;جمع;
54 | 2;2;number;عدد;4;plural;جمع تكسير;جمع تكسير;
55 | 2;2;number;عدد;-;none;لاشيء;;
56 | ## Inlfection case الحالة الإعرابية
57 | 2;3;case;إعراب;U;marfou3;مرفوع;مرفوع;
58 | 2;3;case;إعراب;0;manjzoum; مجزوم;مجزوم;
59 | 2;3;case;إعراب;I;majrour;مجرور;مجرور;
60 | 2;3;case;إعراب;A;mansoub;منصوب;منصوب;
61 | 2;3;case;إعراب;B;mabni;مبني;مبني;
62 | 2;3;case;إعراب;-;undef;لاشيء;;
63 | ## Inflection marks
64 | 2;4;mark;علامة;u;damma;الضمة;الضمة;
65 | 2;4;mark;علامة;a;fatha;الفتحة;الفتحة;
66 | 2;4;mark;علامة;i;kasra;الكسرة;الكسرة;
67 | 2;4;mark;علامة;0;sukun;السكون;السكون;
68 | 2;4;mark;علامة;A;alef;الألف;الألف;
69 | 2;4;mark;علامة;W;waw;الواو;الواو;
70 | 2;4;mark;علامة;Y;yeh;الياء;الياء;
71 | 2;4;mark;علامة;N;noon;ثبوت النون;ثبوت النون;
72 | 2;4;mark;علامة;-;undef;لاشيء;;
73 |
74 |
75 | # Procletics and prefixes
76 | ## Conjuction
77 | 3;1;conjonction;عطف;W;WAW;الواو;;
78 | 3;1;conjonction;عطف;F;FEH;الفاء;;
79 | 3;1;conjonction;عطف;-;undef;لاشيء;;
80 | ## preposition
81 | 3;2;preposition;جر;B;Beh;باء;بالباء;
82 | 3;2;preposition;جر;K;Kaf;كاف;بالكاف;
83 | 3;2;preposition;جر;L;Lam;لام;باللام;
84 | 3;2;preposition;جر;-;undef;لاشيء;;
85 | ## Definition
86 | 3;3;definite;تعريف;L;definited;معرفة;;
87 | 3;3;definite;تعريف;-;indefinite;نكرة;;
88 |
89 |
90 | ## Enclitics
91 | 3;4;encletic;ضمير متصل;H;Heh;ضمير متصل;والضمير المتصل مبني;
92 | 3;4;encletic;ضمير متصل;-;undef;لاشيء;;
93 |
94 | # Special Verb
95 | ## Istiqbal
96 | 4;1;istqbal;استقبال;s;istqbal;استقبال;استقبال;
97 | 4;1;istqbal;استقبال;-;undef;لاشيء;;
98 | ## Voice البناء
99 | 4;2;voice;بناء;a;acive voice;معلوم;مبني للمعلوم;
100 | 4;2;voice;بناء;p;acive voice;مجهول;مبني للمجهول;
101 | 4;2;voice;بناء;-;undef;لاشيء;;
102 | ## tense الزمن
103 | 4;3;tense;زمن;p;past;ماضي;ماضي;
104 | 4;3;tense;زمن;f;present;مضارع;مضارع;
105 | 4;3;tense;زمن;i;imperative;أمر;أمر;
106 | 4;3;tense;زمن;-;undef;لاشيء;;
107 | ## person الشخص
108 | 4;4;person;شخص;I;1st person;متكلم;;
109 | 4;4;person;شخص;Y;2nd person;مخاطب;;
110 | 4;4;person;شخص;H;3rd person;غائب;;
111 | 4;4;person;شخص;-;undef;لاشيء;;
112 |
113 |
114 | #Parameters: must starts by #PARAM:
115 | $PARAM:TAG_PARTS_SIZES=3;4;5;5
116 |
117 | $MAP:المضارع المعلوم=مضارع;معلوم;مرفوع
118 | $MAP:المضارع المجزوم=مضارع;معلوم;مجزوم
119 | $MAP:Noun=اسم
120 | $MAP:y=متعدي
121 | $MAP:الأمر المؤكد=أمر;مؤكذ
122 | $MAP:مضاف=ضمير متصل
123 | $MAP:الأمر=أمر
124 | $MAP:هن=غائب;مؤنث;جمع
125 | $MAP:هم=غائب;مذكر;جمع
126 | $MAP:هما=غائب;مذكر;مثنى
127 | $MAP:المضارع المجهول المنصوب=مضارع;مجهول;منصوب
128 | $MAP:المضارع المجهول المجزوم=مضارع;مجهول;مجزوم
129 | $MAP:مفعول به=ضمير متصل
130 | $MAP:n=لازم
131 | $MAP:هما مؤ=غائب;مؤنث;مثنى
132 | $MAP:هي=غائب;مؤنث;مفرد
133 | $MAP:المضارع المؤكد الثقيل المجهول =مضارع;مجهول;مؤكد
134 | $MAP:هو=غائب;مذكر;مفرد
135 | $MAP:أنتِ=مخاطب;مؤنث;مفرد
136 | $MAP:المضارع المنصوب=مضارع;معلوم;منصوب
137 | $MAP:أنت=مخاطب;مذكر;مفرد
138 | $MAP:الماضي المجهول=ماضي;مجهول
139 | $MAP:أنا=متكلم;مذكر;مفرد
140 | $MAP:الماضي المعلوم=ماضي;معلوم
141 | $MAP:المضارع المؤكد الثقيل=مضارع;معلوم;مؤكد
142 | $MAP:أنتما مؤ=مخاطب;مؤنث;مثنى
143 | $MAP:المضارع المجهول=مضارع;مجهول;مرفوع
144 | $MAP:أنتما=مخاطب;مذكر;مثنى
145 | $MAP:Verb=فعل
146 | $MAP:أنتم=مخاطب;مذكر;جمع
147 | $MAP:تعريف=معرفة
148 | $MAP:أنتن=مخاطب;مؤنث;جمع
149 | $MAP:نحن=متكلم;مذكر;جمع
150 |
151 |
152 | """
153 |
154 | TAG_PARTS_SEP = ';'
155 | TAG_PARTS_SIZES = [3,4,4,4]
156 | TAGSDICT ={}
157 | INVERSE_TAGSDICT = {}
158 | ATTR_TAGSDICT = {}
159 | # Map for different tags
160 | # const for Tense Name
161 | TensePast = u"الماضي المعلوم"
162 | TenseFuture = u"المضارع المعلوم"
163 | TenseImperative = u"الأمر"
164 | TenseConfirmedImperative = u"الأمر المؤكد"
165 | TenseJussiveFuture = u"المضارع المجزوم"
166 | TenseSubjunctiveFuture = u"المضارع المنصوب"
167 | TenseConfirmedFuture = u"المضارع المؤكد الثقيل"
168 |
169 |
170 | TensePassivePast = u"الماضي المجهول"
171 | TensePassiveFuture = u"المضارع المجهول"
172 | TensePassiveJussiveFuture = u"المضارع المجهول المجزوم"
173 | TensePassiveSubjunctiveFuture = u"المضارع المجهول المنصوب"
174 | TensePassiveConfirmedFuture = u"المضارع المؤكد الثقيل المجهول "
175 | TAGSMAP = {
176 | #pronouns FEATURES
177 | u"أنا" : [u'متكلم', u'مفرد']
178 | , u"أنت" : [u'مخاطب', u'مذكر', u'مفرد']
179 | , u"أنتِ" : [u'مخاطب', u'مؤنث', u'مفرد']
180 | , u"هو" : [u'غائب', u'مذكر', u'مفرد']
181 | , u"هي" : [u'غائب', u'مؤنث', u'مفرد']
182 | , u"أنتما" : [u'مخاطب', u'مذكر', u'مثنى']
183 | , u"أنتما مؤ" : [u'مخاطب', u'مؤنث', u'مثنى']
184 | , u"هما" : [u'غائب', u'مذكر', u'مثنى']
185 | , u"هما مؤ" : [u'غائب', u'مؤنث', u'مثنى']
186 | , u"نحن" : [u'متكلم', u'جمع']
187 | , u"أنتم" : [u'مخاطب', u'مذكر', u'جمع']
188 | , u"أنتن" : [u'مخاطب', u'مؤنث', u'جمع']
189 | , u"هم" : [u'غائب', u'مذكر', u'جمع']
190 | , u"هن" : [u'غائب', u'مؤنث', u'جمع'],
191 | #TENSE_FEATURES = [
192 | TensePast : [ u'ماضي', u'معلوم', u"مبني"],
193 | TenseFuture : [ u'مضارع', u'معلوم', u'مرفوع', ],
194 | TenseImperative : [ u'أمر', ],
195 | TenseConfirmedImperative : [ u'أمر', u'مؤكذ', ],
196 | TenseJussiveFuture : [ u'مضارع', u'معلوم', u'مجزوم', ],
197 | TenseSubjunctiveFuture : [ u'مضارع', u'معلوم', u'منصوب', ],
198 | TenseConfirmedFuture : [ u'مضارع', u'معلوم', u'مؤكد', ],
199 |
200 |
201 | TensePassivePast : [ u'ماضي', u'مجهول', u"مبني"],
202 | TensePassiveFuture : [ u'مضارع', u'مجهول', u'مرفوع', ],
203 | TensePassiveJussiveFuture : [ u'مضارع', u'مجهول', u'مجزوم', ],
204 | TensePassiveSubjunctiveFuture : [ u'مضارع', u'مجهول', u'منصوب', ],
205 | TensePassiveConfirmedFuture : [ u'مضارع', u'مجهول', u'مؤكد', ],
206 |
207 | "Verb": [u'فعل'],
208 | "Noun": [u'اسم'],
209 | u"مفعول به": [u'ضمير متصل'],
210 | u"تعريف": [u'معرفة'],
211 | u"n": [u'لازم'],
212 | u"y": [u'متعدي'],
213 | u"مضاف": [u'ضمير متصل'],
214 |
215 | }
216 |
--------------------------------------------------------------------------------
/mysam/tagcoder.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # tag_const.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import os
26 |
27 | try:
28 | import tag_const
29 | import tagconfig
30 | import tagmaker
31 | except:
32 | from . import tag_const
33 | from . import tagconfig
34 | from . import tagmaker
35 |
36 |
37 | class tagCoder(tagmaker.tagMaker):
38 | """
39 | Manage code, decode a tag
40 | """
41 |
42 | def __init__(self, configfile = None):
43 | """Init tha class"""
44 | tagmaker.tagMaker.__init__(self, configfile)
45 | self.reset()
46 |
47 | def encode(self, taglist = []):
48 | """Encode a tag list into string tag.
49 |
50 | Example:
51 | >>> import mysam.tagcoder
52 | >>> tag_coder = mysam.tagcoder.tagCoder()
53 | >>> taglist = [u'اسم', u'ضمير متصل', u'مجرور']
54 | >>> tagstr = tag_coder.encode(taglist)
55 | >>> print(tagstr)
56 | N--;------I;--H
57 |
58 | @param taglist: an given tag list to be coded
59 | @type taglist: string list
60 | @return: a string
61 | @rtype: string
62 | """
63 |
64 | if not taglist:
65 | return u""
66 | self.reset()
67 | for tag in taglist:
68 | self.add(tag)
69 |
70 | return self.__str__()
71 |
72 | def decode(self, tagstring):
73 | """Decode a string tag to get all tags
74 | Example:
75 | >>> import mysam.tagcoder
76 | >>> tag_coder = mysam.tagcoder.tagCoder()
77 | >>> tagcode = 'N--;--I-;----;--H'
78 | >>> print(tag_coder.decode(tagcode)))
79 | [('نوع الكلمة', 'اسم'), ('خاصية', 'لاشيء'), ('جنس', 'لاشيء'), ('عدد', 'لاشيء'), ('شخص', 'متكلم'), ('علامة', 'لاشيء'), ('عطف', 'لاشيء'), ('استقبال', 'لاشيء'), ('ضمير متصل', 'لاشيء')]
80 |
81 | @param tagstring: a string tag to be decoded, if not given, return null
82 | @type tagstring: string
83 | @return: tag list
84 | @rtype: stringlist
85 | """
86 | if not tagstring:
87 | return ""
88 | else:
89 | return self._decode(tagstring)
90 | return tags
91 |
92 | def add_tag(self, tag, tagstring):
93 | """ Add new tag to th tagstring code
94 | Example:
95 | >>> import mysam.tagcoder
96 | >>> tag_coder = mysam.tagcoder.tagCoder()
97 | >>> tagcode = 'V-0;M1H-faU;W--'
98 | >>> tag = "ضمير متصل"
99 | >>> print(tag_coder.add_tag(tag, tagcode))
100 | V-0;M1H-faU;W-H
101 |
102 |
103 | @param tagstring: a string tag to be decoded, if not given, return null
104 | @type tagstring: string
105 | @return: tag list
106 | @rtype: stringlist
107 | """
108 | if not tagstring:
109 | return ""
110 | else:
111 | # decode the string
112 | decoded_taglist = self._decode(tagstring)
113 | # extract values
114 | tag_values = [v for (k,v) in decoded_taglist]
115 | # add tag to tag_values
116 | if tag in tag_values:
117 | return tagstring
118 | else:
119 | tag_values.append(tag)
120 | # encode
121 | return self.encode(tag_values)
122 |
123 | def remove_tag(self, tag, tagstring):
124 | """ remove a tag from tagstring code
125 | Example:
126 | >>> import mysam.tagcoder
127 | >>> tag_coder = mysam.tagcoder.tagCoder()
128 | >>> tagcode = 'V-0;M1H-faU;W-H'
129 | >>> tag = "ضمير متصل"
130 | >>> print(tag_coder.remove_tag(tag, tagcode))
131 | V-0;M1H-faU;W--
132 |
133 |
134 | @param tagstring: a string tag to be decoded, if not given, return null
135 | @type tagstring: string
136 | @return: tag list
137 | @rtype: stringlist
138 | """
139 | if not tagstring:
140 | return ""
141 | else:
142 | # decode the string
143 | decoded_taglist = self._decode(tagstring)
144 | # extract values
145 | tag_values = [v for (k,v) in decoded_taglist]
146 | # add tag to tag_values
147 | if not tag in tag_values:
148 | return tagstring
149 | else:
150 | tag_values.remove(tag)
151 | # encode
152 | return self.encode(tag_values)
153 |
154 |
155 |
156 | if __name__ == "__main__":
157 | pass
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/mysam/tagconfig.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # tag_const.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | try:
25 | from . import tag_const
26 | except:
27 | import tag_const
28 |
29 | import re
30 | import codecs
31 | class tagConfig:
32 | """ Load config from given configuration """
33 | tagsdict ={}
34 | inverse_tagsdict = {}
35 | attr_tagsdict = {}
36 |
37 | def __init__(self,):
38 | # read config fist
39 | pass;
40 | #~ self.load_config()
41 | self.tagsdict ={}
42 | self.inverse_tagsdict ={}
43 | self.attr_tagsdict= {}
44 | self.tagsmap ={}
45 | #parameters
46 | self.tag_parts_sizes =[]
47 |
48 | self.lines =[]
49 | @staticmethod
50 | def str2int(nb):
51 | """ Safe str 2 int conversion """
52 | try:
53 | return int(nb)
54 | except ValueError:
55 | return 0
56 | def load_config(self, config_file = False, debug=False):
57 | """ Load config rules from a file, or use default config file
58 | You can find a tag.config like in doc directory
59 | @param config_file: file to load
60 | @type config_file: string
61 | @param debug: it exist when file is not found
62 | @type debug: boolean
63 | """
64 | # if given file, try to use it, else load
65 | if config_file:
66 | try:
67 | with codecs.open(config_file, 'r', encoding='utf-8') as infile:
68 | self.lines = infile.readlines()
69 | #~ print("load configfile with success")
70 |
71 | except:
72 | if debug:
73 | import sys
74 | print("can't Open file", config_file)
75 | sys.exit()
76 | self.lines = tag_const.TAGS_CONFIG.split("\n")
77 | else:
78 | self.lines = tag_const.TAGS_CONFIG.split("\n")
79 |
80 | for line in self.lines:
81 | line = line.strip("\n")
82 | if not line.startswith('#') and not line.startswith('$') and line:
83 | alist = line.split(";")
84 | alist = [x.strip() for x in alist]
85 | # prepare keys
86 | ar_key = alist[6].strip()
87 | en_key = alist[5].strip()
88 | part_key = self.str2int(alist[0])
89 | pos_key = self.str2int(alist[1])
90 | code = alist[4]
91 | attr = alist[2]
92 | attr_ar = alist[3]
93 | key = u":".join([str(part_key), str(pos_key), code])
94 | # extract fields
95 | adict = {
96 | 'part': part_key,
97 | 'pos': pos_key,
98 | 'attr': alist[2],
99 | 'ar_attr': alist[3],
100 | 'code': code ,
101 | 'value': alist[5],
102 | 'ar_value': alist[6],
103 | 'inflect': alist[7],
104 | }
105 | # value based index
106 | self.tagsdict[ar_key] = adict
107 | self.tagsdict[en_key] = adict
108 | # code based index
109 | self.inverse_tagsdict[key] = adict
110 | #attrib based index
111 | self.attr_tagsdict[attr] = adict
112 | self.attr_tagsdict[attr_ar] = adict
113 | elif line.startswith('$PARAM:'):
114 | alist = line[7:].split("=")
115 | if len(alist) >= 2:
116 | field_name = alist[0]
117 | values = alist[1].split(";")
118 | if field_name == "TAG_PARTS_SIZES":
119 | self.tag_parts_sizes = [self.str2int(v) for v in values]
120 | elif line.startswith('$MAP:'):
121 | alist = line[5:].split("=")
122 | if len(alist) >= 2:
123 | tag = alist[0]
124 | values = alist[1].split(";")
125 | self.tagsmap[tag] = values
126 |
127 | #~ # load on Global variables
128 | #~ tag_const.TAGSDICT = self.tagsdict
129 | #~ tag_const.INVERSE_TAGSDICT =self.inverse_tagsdict
130 | #~ tag_const.ATTR_TAGSDICT =self.attr_tagsdict
131 | #~ # if structure not defined, the default structure is used.
132 | #~ if self.tag_parts_sizes:
133 | #~ tag_const.TAG_PARTS_SIZES = self.tag_parts_sizes
134 | #~ if self.tagsmap:
135 | #~ tag_const.TAGSMAP = self.tagsmap
136 |
137 | def markdown(self,):
138 | """ Dispaly rules and tags in markdown style.
139 | read lines from load config, the create a Markdown text to document out tag ste system
140 | @return: text.
141 | @rtype: unicode text
142 | """
143 | textlines =[]
144 | textlines.append("# Table of configuration")
145 | #~ lines = tag_const.TAGS_CONFIG.split("\n")
146 | # make headers + table seprator
147 | headers = self.lines[0].strip('\n').replace(';','|')
148 | textlines.append("## Columns description")
149 | textlines.append("* " + self.lines[0].replace(';','\n* '))
150 | headers += "\n" +re.sub('[^|]','-', headers)
151 | # avoid the first line
152 | for line in self.lines[1:]:
153 | line = line.strip('\n')
154 | if line and not line.startswith('$'):
155 | if line.startswith('##'):
156 | # is a sub class
157 | pass;
158 | # to do makr it
159 | elif line.startswith('#'):
160 | textlines.append('\n')
161 | textlines.append(u"#"+line)
162 | textlines.append('\n')
163 | textlines.append(headers)
164 | else:
165 | textlines.append(line.replace(';','|'))
166 | return u"\n".join(textlines)
167 |
168 | def markdown_cat(self,):
169 | """ Dispaly rules and tags in markdown style as categories.
170 | read lines from load config, the create a Markdown text to document out tag ste system
171 | @return: text.
172 | @rtype: unicode text
173 | """
174 | #~ lines = tag_const.TAGS_CONFIG.split("\n")
175 | textlines =[]
176 | textlines.append("# Description")
177 | textlines.append("## Structure")
178 | textlines.append("\tTAG_PARTS_SIZES=[%s]"%tag_const.TAG_PARTS_SIZES)
179 | textlines.append("\tTAG_PARTS_SEP ='%s'"%tag_const.TAG_PARTS_SEP)
180 | structure = []
181 | for i in range(len(tag_const.TAG_PARTS_SIZES)):
182 | structure.append('-'*tag_const.TAG_PARTS_SIZES[i])
183 | structure = tag_const.TAG_PARTS_SEP.join(structure)
184 | textlines.append("\tStructure =[%s]"%structure)
185 | textlines.append("## Parts")
186 |
187 | for line in self.lines[1:]:
188 | line = line.strip('\n')
189 | if line and not line.startswith('$'):
190 | if line.startswith('##'):
191 | # is a sub class
192 | textlines.append(u'\t\t%s'%line[2:])
193 | # to do makr it
194 | elif line.startswith('#'):
195 | textlines.append(u"\t%s"%line[1:])
196 | textlines.append("## Detailled")
197 | for line in self.lines[1:]:
198 | line = line.strip('\n')
199 | if line and not line.startswith('$'):
200 | if line.startswith('##'):
201 | # is a sub class
202 | textlines.append(u'\t%s:'%line[2:])
203 | # to do makr it
204 | elif line.startswith('#'):
205 | textlines.append(u"#%s:\n"%line)
206 | else:
207 | # print a sub category
208 | alist = line.split(";")
209 | textlines.append("\t\t "+ u"%s: %s"%(alist[4], alist[5]))
210 |
211 |
212 | return u"\n".join(textlines)
213 | def markdown_map(self,):
214 | """ Dispaly MAP tags and tags in markdown style as categories.
215 | read lines from load config, the create a Markdown text to document out tag ste system
216 | @return: text.
217 | @rtype: unicode text
218 | """
219 | textlines =[]
220 | ## prepare the Mapping
221 | textlines.append("\n# TAGS MAP")
222 | textlines.append("Feature|maps")
223 | textlines.append("-------|----")
224 |
225 | for k in tag_const.TAGSMAP:
226 | textlines.append("%s|%s"%(k, u', '.join(tag_const.TAGSMAP[k])))
227 |
228 | return u"\n".join(textlines)
229 |
230 | if __name__ == "__main__":
231 | import pandas as pd
232 | # set encoding
233 | import sys
234 | reload(sys)
235 | sys.setdefaultencoding('utf-8')
236 |
237 | configuer = tagConfig()
238 | configuer.load_config("config/tag.config", debug=True)
239 | df = pd.DataFrame(tag_const.TAGSDICT)
240 | print('****tagdict ****')
241 | print(df)
242 | df2 = pd.DataFrame(tag_const.INVERSE_TAGSDICT)
243 | print('****inverse tagdict ****')
244 | print(df2)
245 | df3 = pd.DataFrame(tag_const.INVERSE_TAGSDICT)
246 | print('****attr tagdict ****')
247 | print(df3)
248 | print("************Markdown ******************")
249 | md = configuer.markdown_cat()
250 | print(md.encode('utf8'))
251 | mdc = configuer.markdown()
252 | print(mdc.encode('utf8'))
253 |
--------------------------------------------------------------------------------
/mysam/taginflector.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # tag_const.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import os
26 |
27 | try:
28 | import tag_const
29 | import tagconfig
30 | import tagmaker
31 | except:
32 | from . import tag_const
33 | from . import tagconfig
34 | from . import tagmaker
35 | from . import tag_const_inflect
36 |
37 | class tagInflector(tagmaker.tagMaker):
38 | """
39 | Manage code, decode a tag
40 | """
41 |
42 | def __init__(self, configfile = None):
43 | """Init tha class"""
44 | tagmaker.tagMaker.__init__(self, configfile)
45 | self.reset()
46 | # print("INVERSE_TAGSMAP", self.inverse_tagsmap)
47 | self.tag_tense_pronoun_inflection = tag_const_inflect.TABLE_TENSE_PRONOUN_INFLECTION
48 | def _get_pronoun(self, person, gender, number):
49 | """
50 | Get pronoun accoriding to person, number, gender
51 | """
52 | key = u"-".join([person, gender, number])
53 | return self.inverse_tagsmap.get(key, "")
54 |
55 | def _get_verb_mark(self, tagstring ):
56 | """
57 | get verb mark based on tagstring
58 | """
59 | tense = self.get_value('زمن', tagstring)
60 | voice = self.get_value(u'بناء', tagstring)
61 | person = self.get_value(u'شخص', tagstring)
62 | number = self.get_value(u'عدد', tagstring)
63 | gender = self.get_value(u'جنس', tagstring)
64 | # get the pronoun name
65 | pronoun = self._get_pronoun(person, gender, number)
66 | mood = self.get_value(u'إعراب', tagstring)
67 | # get the tense original name
68 |
69 | if tense == "مضارع":
70 | tense_key = "-".join([tense, voice, mood])
71 | else:
72 | tense_key = "-".join([tense,voice])
73 | tense_key = self.inverse_tagsmap.get(tense_key,"")
74 | # extract inflect_dict
75 | inflect_dict = self.tag_tense_pronoun_inflection.get(tense_key, {}).get(pronoun, {})
76 |
77 | # return " ".join([tense_key, pronoun, " ".join(inflect_dict.values())])
78 | # format the inflection string
79 | inflect_list = [inflect_dict.get("description",""),
80 | inflect_dict.get("case",""),
81 | inflect_dict.get("cause",""),
82 | inflect_dict.get("subject",""),
83 | inflect_dict.get("extra",""),
84 | ]
85 | # remove empty strings
86 | inflect_list = [x for x in inflect_list if x]
87 | inflect_string = " ".join(inflect_list)
88 | return inflect_string
89 |
90 | def inflect_noun(self, tagstring=False):
91 | """
92 | get inflection for a noun
93 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
94 | @type tagstring: string
95 | @return: string
96 | @rtype: string
97 | """
98 | if not tagstring:
99 | tagstring = self.__str__()
100 | inflct = []
101 | if self.has_tag(u"اسم", tagstring):
102 | # inflect = Syntaxtic classe
103 | # مفعول به منصوب وعلامة نصبه الفتحة
104 | #نعت منصوب وعلامةنصبه الياء لأنه مثنى
105 | #مبتدأ مرفوع وعلامة رفعه الواو لأنه جمع مذكر سالم
106 | # case
107 | case = self.get_inflect(u'إعراب', tagstring)
108 | if case:
109 | case_part = u"اسم %s"%case
110 | inflct.append(case_part)
111 | # Jar
112 | if self.has_tag(u"مجرور", tagstring):
113 | jar = self.get_inflect(u'جر', tagstring)
114 | if jar:
115 | jar_part = jar
116 | inflct.append(jar_part)
117 | # inflect Mark
118 | mark =self.get_inflect(u'علامة', tagstring)
119 | mark_value =self.get_value(u'علامة', tagstring)
120 | if mark:
121 | #علامة الإعراب
122 | # وعلامة رفعه الضمة
123 | mark_part =""
124 | # علة علامة الإعراب
125 | # وعلامة رفعه الألف لأنه مثنى
126 | cause_part =""
127 | if case == u"مبني":
128 | mark_part = u"على %s"%mark
129 | else:
130 | # استخراج الحالة
131 | #~ مرفوع => رفعه
132 | #~ منصوب => نصبه
133 | #~ مجرور => جره
134 | case_mark = ""
135 | if case == u"مرفوع":
136 | case_mark = u"رفعه"
137 | elif case == u"منصوب":
138 | case_mark = u"نصبه"
139 | elif case == u"مجرور":
140 | case_mark = u"جرّه"
141 |
142 | mark_part = u"وعلامة %s %s"%(case_mark, mark)
143 |
144 | # mark cause
145 |
146 | if self.has_tag(u"مثنى", tagstring):
147 | cause_part = u"لأنه مثنى"
148 | elif self.has_tag(u'مؤنث', tagstring) and self.has_tag(u"جمع", tagstring):
149 | cause_part = u"لأنه جمع مؤنث سالم"
150 | elif self.has_tag(u'مذكر', tagstring) and self.has_tag(u"جمع", tagstring):
151 | cause_part = u"لأنه جمع مذكر سالم"
152 | elif self.has_tag(u'مجرور', tagstring) and self.has_tag(u"ممنوع من الصرف", tagstring):
153 | cause_part = u"لأنه ممنوع من الصرف"
154 | inflct.append(mark_part)
155 | inflct.append(cause_part)
156 | #attached pronoun
157 | add_p = self.get_inflect(u'ضمير متصل', tagstring)
158 | if add_p:
159 | add_part = u"وهو مضاف، %s في محل جر مضاف إليه"%add_p
160 | inflct.append(add_part)
161 | else: # no case
162 | word_type = self.get_value(u'نوع الكلمة', tagstring)
163 | if word_type:
164 | inflct.append(word_type)
165 | return u" ".join(inflct)
166 | def inflect_verb(self, tagstring):
167 | """
168 | get inflection for a noun
169 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
170 | @type tagstring: string
171 | @return: string
172 | @rtype: string
173 | """
174 | if not tagstring:
175 | tagstring = self.__str__()
176 | inflct = []
177 | if self.has_tag(u"فعل", tagstring):
178 | # inflect = Syntaxtic classe
179 | # مفعول به منصوب وعلامة نصبه الفتحة
180 | #نعت منصوب وعلامةنصبه الياء لأنه مثنى
181 | #مبتدأ مرفوع وعلامة رفعه الواو لأنه جمع مذكر سالم
182 | # tense:
183 | inflect_conj = self._get_verb_mark(tagstring)
184 | if inflect_conj:
185 | inflct.append(inflect_conj)
186 |
187 | # tense = self.get_inflect(u'زمن', tagstring)
188 | # voice = self.get_inflect(u'بناء', tagstring)
189 | # inflct.append(u"فعل")
190 | # inflct.append(tense)
191 | # inflct.append(voice)
192 | # # case
193 | # case = self.get_inflect(u'إعراب', tagstring)
194 | # #~ print((u"###%s####"%case), tagstring)
195 | # if case:
196 | # case_part = case
197 | # inflct.append(case_part)
198 | #
199 | # # inflect Mark
200 | # mark =self.get_inflect(u'علامة', tagstring)
201 | # mark_value = self.get_value(u'علامة', tagstring)
202 | # if mark:
203 | # #علامة الإعراب
204 | # # وعلامة رفعه الضمة
205 | # mark_part =""
206 | # # علة علامة الإعراب
207 | # # وعلامة رفعه الألف لأنه مثنى
208 | # cause_part =""
209 | # if case == u"مبني":
210 | # mark_part = u"على %s"%mark
211 | # else:
212 | # # استخراج الحالة
213 | # #~ مرفوع => رفعه
214 | # #~ منصوب => نصبه
215 | # #~ مجرور => جره
216 | # case_mark = ""
217 | # if case == u"مرفوع":
218 | # case_mark = u"رفعه"
219 | # elif case == u"منصوب":
220 | # case_mark = u"نصبه"
221 | # elif case == u"مجزوم":
222 | # case_mark = u"جزمه"
223 | #
224 | # mark_part = u"وعلامة %s %s"%(case_mark, mark)
225 | #
226 | # # mark cause
227 | #
228 | # condition_5verbs = (self.has_tag(u"مثنى", tagstring)
229 | # or (self.has_tag(u'مذكر', tagstring) and self.has_tag(u"جمع", tagstring))
230 | # or (self.has_tag(u'مؤنث', tagstring) and self.has_tag(u"مخاطب", tagstring) and self.has_tag(u"مفرد", tagstring))
231 | # )
232 | # if condition_5verbs:
233 | # cause_part = u"لأنه من الأفعال الخمسة"
234 | # inflct.append(mark_part)
235 | # inflct.append(cause_part)
236 | #attached pronoun
237 |
238 | add_p = self.get_inflect(u'ضمير متصل', tagstring)
239 | #~ print((u"H###%s####"%add_p))
240 | if add_p:
241 | add_part = u"%s في محل نصب مفعول به"%add_p
242 | inflct.append(add_part)
243 | else: # no case
244 | word_type = self.get_value(u'نوع الكلمة', tagstring)
245 | if word_type:
246 | inflct.append(word_type)
247 | return u" ".join(inflct)
248 | def inflect_tool(self, tagstring = False):
249 | """
250 | """
251 | return u""
252 | def inflect(self, tagstring = False):
253 | """
254 | Display inlfection in traditional way
255 | عرض إعراب الكلمة حسب التقاليد
256 |
257 | Example:
258 | >>> tag_maker = tagmaker.tagMaker()
259 | >>> tagcode = 'N--;--I-;----;---'
260 | >>> print(tag_maker.inflect(tagcode))
261 | اسم مجرور وعلامة جرّه الياء لأنه جمع مذكر سالم وهو مضاف، والضمير المتصل مبني في محل جر مضاف إليه
262 |
263 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
264 | @type tagstring: string
265 | @return: string
266 | @rtype: string
267 | """
268 | if not tagstring:
269 | tagstring = self.__str__()
270 | inflct = []
271 | if self.has_tag(u"اسم", tagstring):
272 | return self.inflect_noun(tagstring)
273 | elif self.has_tag(u"فعل", tagstring):
274 | return self.inflect_verb(tagstring)
275 | elif self.has_tag(u"أداة", tagstring):
276 | return self.inflect_tool(tagstring)
277 | else:
278 | word_type = self.get_value(u'نوع الكلمة', tagstring)
279 | if word_type:
280 | inflct.append(word_type)
281 | return u" ".join(inflct)
282 |
283 |
284 | if __name__ == "__main__":
285 | taglists = [[u'اسم', u'هاء', u'مجرور',"مصدر"],
286 | u'تعريف::مرفوع:متحرك:ينون:::'.split(":"),
287 | u'المضارع المعلوم:هو:::n:'.split(":"),
288 | u':مضاف:مجرور:متحرك:ينون:::'.split(':'),
289 | ]
290 | tag_maker = tagMaker("config/tag.config")
291 |
292 | for taglist in taglists:
293 | tag_maker.reset()
294 | tag_maker.encode(taglist)
295 | print(u"+".join(taglist))
296 | tagstr = str(tag_maker)
297 | print(tagstr)
298 | # decode a unifed tag string
299 | print(tag_maker.repr(tag_maker.decode()))
300 |
301 |
302 |
303 |
--------------------------------------------------------------------------------
/mysam/tagmaker.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # tag_const.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import os
25 | # ~ if __name__ == "__main__":
26 |
27 | try:
28 | import tag_const
29 | import tagconfig
30 | except:
31 | from . import tag_const
32 | from . import tagconfig
33 |
34 |
35 | class tagMaker:
36 | """
37 | Manage tags, create, code, decode a tag
38 | """
39 |
40 | def __init__(self, configfile = None):
41 | """Init tha class"""
42 | # read config first
43 | #~ self.load_config()
44 | self.debug = False
45 | self.lang ="ar"
46 | if not configfile:
47 | # get specific config file
48 | configfile = os.path.join(os.path.dirname(__file__) , "config/tag.config")
49 | if configfile:
50 | #~ print("Load a config file")
51 | configuer = tagconfig.tagConfig()
52 | configuer.load_config(configfile)
53 | # load on Global variables
54 | self.tagsdict = configuer.tagsdict
55 | self.inverse_tagsdict = configuer.inverse_tagsdict
56 | self.attr_tagsdict = configuer.attr_tagsdict
57 | # if structure not defined, the default structure is used.
58 | if configuer.tag_parts_sizes:
59 | self.tag_parts_sizes = configuer.tag_parts_sizes
60 | else:
61 | self.tag_parts_sizes = []
62 | if configuer.tagsmap:
63 | self.tagsmap = configuer.tagsmap
64 | else:
65 | self.tagsmap = configuer.tagsmap
66 | self.tag_parts_sep = tag_const.TAG_PARTS_SEP
67 |
68 | else:
69 | # load on Global variables
70 | self.tagsdict = tag_const.TAGSDICT
71 | self.inverse_tagsdict = tag_const.INVERSE_TAGSDICT
72 | self.attr_tagsdict = tag_const.ATTR_TAGSDICT
73 | # if structure not defined, the default structure is used.
74 | self.tag_parts_sizes = tag_const.TAG_PARTS_SIZES
75 | self.tag_parts_sep = tag_const.TAG_PARTS_SEP
76 | self.tagsmap = tag_const.TAGSMAP
77 | # prepare the tag maker
78 | # inverse tag map
79 | self.inverse_tagsmap = {}
80 | for key in self.tagsmap:
81 | newkey = "-".join(self.tagsmap[key])
82 | newvalue = key
83 | self.inverse_tagsmap[newkey]= newvalue
84 | self.reset()
85 |
86 |
87 | def set_config(self,configfile):
88 | """ set a config to encode tags"""
89 | configueur = tagconfig.tagConfig()
90 | configueur.load_config(configfile)
91 |
92 | def reset(self,):
93 | """ reset the taglist to make a new"""
94 | # init taglist
95 | self.taglist = []
96 | for i in range(len(self.tag_parts_sizes)):
97 | self.taglist.append(['-']*self.tag_parts_sizes[i])
98 |
99 | def __str__(self,):
100 | """ prepare list to be printed
101 | @return: a string
102 | @rtype: string
103 | """
104 | # join sub lists without separater,
105 | # the join parts by separator
106 | return self.tag_parts_sep.join([u"".join(x) for x in self.taglist])
107 | @staticmethod
108 | def repr(obj):
109 | """ prepare list to be printed
110 | @return: a string
111 | @rtype: string
112 | """
113 | if type(obj) is dict:
114 | return repr(obj).replace("},","},\n")
115 | else:
116 | return repr(obj)
117 |
118 | def add(self, tag):
119 | """ add a new tag to the taglist
120 | Example:
121 | >>> tag_maker = tagmaker.tagMaker()
122 | >>> tagcode = 'N--;--I-;----;---'
123 | >>> tag_new = u"تعريف"
124 | >>> tag_maker.add(tag_new)
125 | >>> tag_new = u"اسم"
126 | >>> tag_maker.add(tag_new)
127 | >>> print(str(tag_maker))
128 | N--;----;--L-;----
129 |
130 | @param tag: a tag
131 | @type tag: unicode
132 | """
133 | debug = self.debug
134 | # if tag names are differents, it can contain many tags
135 | taglist =[]
136 | if not tag in self.tagsdict:
137 | taglist = self.tagsmap.get(tag,[])
138 | if debug: print("***",u";;".join(taglist))
139 | else:
140 | taglist =[tag,]
141 | # if the tag exist in tagsdict configuration
142 | # choose value and add it to a position
143 | for tg in taglist:
144 | if tg in self.tagsdict:
145 | if debug: print("***//",tg)
146 | part = self.tagsdict[tg]['part'] -1
147 | pos = self.tagsdict[tg]['pos']-1
148 | code = self.tagsdict[tg]['code']
149 | self.taglist[part][pos] = code
150 | else:
151 | if debug: print("***Unrecoginzed tag//",tg)
152 |
153 |
154 | def _encode(self, taglist = []):
155 | """Encode a tag list into string tag.
156 |
157 | Example:
158 | >>> import mysam.tagmaker as tagmaker
159 | >>> tag_maker = tagmaker.tagMaker()
160 | >>> taglist = [u'اسم', u'مضير متصل', u'مجرور']
161 | >>> tag_maker.encode(taglist)
162 | >>> tagstr = str(tag_maker)
163 | >>> print(tagstr)
164 | N--;--I-;----;----
165 |
166 | @param taglist: an given tag list to be coded
167 | @type taglist: string list
168 | @return: a string
169 | @rtype: string
170 | """
171 | if not taglist:
172 | return u""
173 | for tag in taglist:
174 | self.add(tag)
175 | return self.__str__()
176 |
177 | def _decode(self, tagstring = False):
178 | """Decode a string tag to get all tags
179 | Example:
180 | >>> import mysam.tagmaker as tagmaker
181 | >>> tag_maker = tagmaker.tagMaker()
182 | >>> tagcode = 'N--;--I-;----;---'
183 | >>> print(tag_maker.decode(tagcode)))
184 | [(u'نوع الكلمة', u'اسم'), (u'جنس', u'لاشيء'), (u'عدد', u'لاشيء'), (u'إعراب', u'مجرور'), (u'علامة', u'لاشيء'), (u'عطف', u'لاشيء'), (u'جر', u'لاشيء'), (u'تعريف', u'نكرة'), (u'ضمير متصل', u'لاشيء'), (u'استقبال', u'لاشيء'), (u'بناء', u'لاشيء'), (u'زمن', u'لاشي
185 |
186 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
187 | @type tagstring: string
188 | @return: tag list
189 | @rtype: stringlist
190 | """
191 | if not tagstring:
192 | tagstring = self.__str__()
193 | parts = tagstring.split(self.tag_parts_sep)
194 | if self.lang == "ar":
195 | value_key = 'ar_value'
196 | attr_key = 'ar_attr'
197 | else:
198 | value_key = 'value'
199 | attr_key = 'attr'
200 |
201 | tags = []
202 | # read codes
203 | for ip, part in enumerate(parts):
204 | for i in range(len(part)):
205 | code = part[i]
206 | key = u":".join([str(ip+1), str(i+1), code])
207 | #~ print key
208 | tag = self.inverse_tagsdict.get(key,{}).get(value_key,"")
209 | attr = self.inverse_tagsdict.get(key,{}).get(attr_key,"")
210 | if tag:
211 | tags.append((attr, tag))
212 |
213 | return tags
214 |
215 | def inflect_noun(self, tagstring=False):
216 | """
217 | get inflection for a noun
218 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
219 | @type tagstring: string
220 | @return: string
221 | @rtype: string
222 | """
223 | if not tagstring:
224 | tagstring = self.__str__()
225 | inflct = []
226 | if self.has_tag(u"اسم", tagstring):
227 | # inflect = Syntaxtic classe
228 | # مفعول به منصوب وعلامة نصبه الفتحة
229 | #نعت منصوب وعلامةنصبه الياء لأنه مثنى
230 | #مبتدأ مرفوع وعلامة رفعه الواو لأنه جمع مذكر سالم
231 | # case
232 | case = self.get_inflect(u'إعراب', tagstring)
233 | if case:
234 | case_part = u"اسم %s"%case
235 | inflct.append(case_part)
236 | # Jar
237 | if self.has_tag(u"مجرور", tagstring):
238 | jar = self.get_inflect(u'جر', tagstring)
239 | if jar:
240 | jar_part = jar
241 | inflct.append(jar_part)
242 | # inflect Mark
243 | mark =self.get_inflect(u'علامة', tagstring)
244 | mark_value =self.get_value(u'علامة', tagstring)
245 | if mark:
246 | #علامة الإعراب
247 | # وعلامة رفعه الضمة
248 | mark_part =""
249 | # علة علامة الإعراب
250 | # وعلامة رفعه الألف لأنه مثنى
251 | cause_part =""
252 | if case == u"مبني":
253 | mark_part = u"على %s"%mark
254 | else:
255 | # استخراج الحالة
256 | #~ مرفوع => رفعه
257 | #~ منصوب => نصبه
258 | #~ مجرور => جره
259 | case_mark = ""
260 | if case == u"مرفوع":
261 | case_mark = u"رفعه"
262 | elif case == u"منصوب":
263 | case_mark = u"نصبه"
264 | elif case == u"مجرور":
265 | case_mark = u"جرّه"
266 |
267 | mark_part = u"وعلامة %s %s"%(case_mark, mark)
268 |
269 | # mark cause
270 |
271 | if self.has_tag(u"مثنى", tagstring):
272 | cause_part = u"لأنه مثنى"
273 | elif self.has_tag(u'مؤنث', tagstring) and self.has_tag(u"جمع", tagstring):
274 | cause_part = u"لأنه جمع مؤنث سالم"
275 | elif self.has_tag(u'مذكر', tagstring) and self.has_tag(u"جمع", tagstring):
276 | cause_part = u"لأنه جمع مذكر سالم"
277 | elif self.has_tag(u'مجرور', tagstring) and self.has_tag(u"ممنوع من الصرف", tagstring):
278 | cause_part = u"لأنه ممنوع من الصرف"
279 | inflct.append(mark_part)
280 | inflct.append(cause_part)
281 | #attached pronoun
282 | add_p = self.get_inflect(u'ضمير متصل', tagstring)
283 | if add_p:
284 | add_part = u"وهو مضاف، %s في محل جر مضاف إليه"%add_p
285 | inflct.append(add_part)
286 | else: # no case
287 | word_type = self.get_value(u'نوع الكلمة', tagstring)
288 | if word_type:
289 | inflct.append(word_type)
290 | return u" ".join(inflct)
291 |
292 | def inflect_verb(self, tagstring):
293 | """
294 | get inflection for a noun
295 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
296 | @type tagstring: string
297 | @return: string
298 | @rtype: string
299 | """
300 | if not tagstring:
301 | tagstring = self.__str__()
302 | inflct = []
303 | if self.has_tag(u"فعل", tagstring):
304 | # inflect = Syntaxtic classe
305 | # مفعول به منصوب وعلامة نصبه الفتحة
306 | #نعت منصوب وعلامةنصبه الياء لأنه مثنى
307 | #مبتدأ مرفوع وعلامة رفعه الواو لأنه جمع مذكر سالم
308 | # tense:
309 | tense = self.get_inflect(u'زمن', tagstring)
310 | voice = self.get_inflect(u'بناء', tagstring)
311 | inflct.append(u"فعل")
312 | inflct.append(tense)
313 | inflct.append(voice)
314 | # case
315 | case = self.get_inflect(u'إعراب', tagstring)
316 | #~ print((u"###%s####"%case), tagstring)
317 | if case:
318 | case_part = case
319 | inflct.append(case_part)
320 |
321 | # inflect Mark
322 | mark =self.get_inflect(u'علامة', tagstring)
323 | mark_value =self.get_value(u'علامة', tagstring)
324 | if mark:
325 | #علامة الإعراب
326 | # وعلامة رفعه الضمة
327 | mark_part =""
328 | # علة علامة الإعراب
329 | # وعلامة رفعه الألف لأنه مثنى
330 | cause_part =""
331 | if case == u"مبني":
332 | mark_part = u"على %s"%mark
333 | else:
334 | # استخراج الحالة
335 | #~ مرفوع => رفعه
336 | #~ منصوب => نصبه
337 | #~ مجرور => جره
338 | case_mark = ""
339 | if case == u"مرفوع":
340 | case_mark = u"رفعه"
341 | elif case == u"منصوب":
342 | case_mark = u"نصبه"
343 | elif case == u"مجزوم":
344 | case_mark = u"جزمه"
345 |
346 | mark_part = u"وعلامة %s %s"%(case_mark, mark)
347 |
348 | # mark cause
349 |
350 | condition_5verbs = (self.has_tag(u"مثنى", tagstring)
351 | or (self.has_tag(u'مذكر', tagstring) and self.has_tag(u"جمع", tagstring))
352 | or (self.has_tag(u'مؤنث', tagstring) and self.has_tag(u"مخاطب", tagstring) and self.has_tag(u"مفرد", tagstring))
353 | )
354 | if condition_5verbs:
355 | cause_part = u"لأنه من الأفعال الخمسة"
356 | inflct.append(mark_part)
357 | inflct.append(cause_part)
358 | #attached pronoun
359 | add_p = self.get_inflect(u'ضمير متصل', tagstring)
360 | #~ print((u"H###%s####"%add_p))
361 | if add_p:
362 | add_part = u"%s في محل نصب مفعول به"%add_p
363 | inflct.append(add_part)
364 | else: # no case
365 | word_type = self.get_value(u'نوع الكلمة', tagstring)
366 | if word_type:
367 | inflct.append(word_type)
368 | return u" ".join(inflct)
369 | def inflect_tool(self, tagstring = False):
370 | """
371 | """
372 | return u""
373 |
374 | def inflect(self, tagstring = False):
375 | """
376 | Display inlfection in traditional way
377 | عرض إعراب الكلمة حسب التقاليد
378 |
379 | Example:
380 | >>> tag_maker = tagmaker.tagMaker()
381 | >>> tagcode = 'N--;--I-;----;---'
382 | >>> print(tag_maker.inflect(tagcode))
383 | اسم مجرور وعلامة جرّه الياء لأنه جمع مذكر سالم وهو مضاف، والضمير المتصل مبني في محل جر مضاف إليه
384 |
385 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
386 | @type tagstring: string
387 | @return: string
388 | @rtype: string
389 | """
390 | if not tagstring:
391 | tagstring = self.__str__()
392 | inflct = []
393 | if self.has_tag(u"اسم", tagstring):
394 | return self.inflect_noun(tagstring)
395 | elif self.has_tag(u"فعل", tagstring):
396 | return self.inflect_verb(tagstring)
397 | elif self.has_tag(u"أداة", tagstring):
398 | return self.inflect_tool(tagstring)
399 | else:
400 | word_type = self.get_value(u'نوع الكلمة', tagstring)
401 | if word_type:
402 | inflct.append(word_type)
403 | return u" ".join(inflct)
404 |
405 | def has_tag(self, tag, tagstring = False):
406 | """
407 | Look up if the tag exists in a string tag
408 | Example:
409 | >>> tag_maker = tagmaker.tagMaker()
410 | >>> tagcode = 'N--;--I-;----;---'
411 | >>> tag_new = u"تعريف"
412 | >>> tag_maker.add(tag_new)
413 | >>> tag_new = u"اسم"
414 | >>> tag_maker.add(tag_new)
415 | >>> print(str(tag_maker))
416 | N--;----;--L-;----
417 |
418 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
419 | @type tagstring: string
420 | @return: boolean
421 | @rtype: boolean
422 | """
423 | if not tagstring:
424 | tagstring = self.__str__()
425 | parts = tagstring.split(self.tag_parts_sep)
426 | if tag not in self.tagsdict:
427 | return False
428 | else:
429 | part = self.tagsdict[tag]['part']
430 | pos = self.tagsdict[tag]['pos']
431 | code = self.tagsdict[tag]['code']
432 | if parts[part-1][pos-1] == code:
433 | return True
434 | else:
435 | return False
436 | return False
437 |
438 | def exists_attr(self, attr, tagstring = False):
439 | """
440 | test if attribute is enabled, for example, جر is ok, if tag code is B, K, L, is not if code is '-'
441 | @param attr: attribute to lookup
442 | @type attr: string
443 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
444 | @type tagstring: string
445 | @return: boolean
446 | @rtype: boolean
447 | """
448 | deco = self.decode_attr(attr, tagstring)
449 | return bool(deco)
450 |
451 | def get_value(self, attr, tagstring=False):
452 | """
453 | Return the value of attribute
454 | @param attr: attribute to lookup
455 | @type attr: string
456 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
457 | @type tagstring: string
458 | @return: the value
459 | @rtype: string
460 | """
461 | deco = self.decode_attr(attr, tagstring)
462 | if deco:
463 | if self.lang == "ar":
464 | return deco.get('ar_value','')
465 | else:
466 | return deco.get('value','')
467 | return ''
468 |
469 | def get_inflect(self, attr, tagstring=False):
470 | """
471 | Return the inflect text of attribute
472 | @param attr: attribute to lookup
473 | @type attr: string
474 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
475 | @type tagstring: string
476 | @return: the inflection
477 | @rtype: string
478 | """
479 | deco = self.decode_attr(attr, tagstring)
480 | if deco:
481 | return deco.get('inflect','')
482 | return ''
483 |
484 |
485 | def decode_attr(self, attr, tagstring = False):
486 | """
487 | Decode an attribute
488 | @param attr: attribute to lookup
489 | @type attr: string
490 | @param tagstring: a string tag to be decoded, if not given the internal tag string is decoded.
491 | @type tagstring: string
492 | @return: the attribute dict
493 | @rtype: dict of string
494 | """
495 | if not tagstring:
496 | tagstring = self.__str__()
497 | parts = tagstring.split(self.tag_parts_sep)
498 | if attr not in self.attr_tagsdict:
499 | return {}
500 | else:
501 | part = self.attr_tagsdict[attr]['part']
502 | pos = self.attr_tagsdict[attr]['pos']
503 | code = parts[part-1][pos-1]
504 | if code == '-':
505 | return {}
506 | else:
507 | key = u":".join([str(part), str(pos), code])
508 | return self.inverse_tagsdict.get(key,{})
509 | return {}
510 |
511 |
512 |
513 | if __name__ == "__main__":
514 | taglists = [[u'اسم', u'هاء', u'مجرور',"مصدر"],
515 | u'تعريف::مرفوع:متحرك:ينون:::'.split(":"),
516 | u'المضارع المعلوم:هو:::n:'.split(":"),
517 | u':مضاف:مجرور:متحرك:ينون:::'.split(':'),
518 | ]
519 | tag_maker = tagMaker("config/tag.config")
520 |
521 | for taglist in taglists:
522 | tag_maker.reset()
523 | tag_maker.encode(taglist)
524 | print(u"+".join(taglist))
525 | tagstr = str(tag_maker)
526 | print(tagstr)
527 | # decode a unifed tag string
528 | print(tag_maker.repr(tag_maker.decode()))
529 |
530 |
531 |
532 |
--------------------------------------------------------------------------------
/requirements:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/linuxscout/mysam-tagmanager/9fb18f7919391c8f3ac4e94c2add68b119195edc/requirements
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/python
2 | from setuptools import setup
3 |
4 | # to install type:
5 | # python setup.py install --root=/
6 | def readme():
7 | with open('README.md') as f:
8 | return f.read()
9 |
10 | setup (name='mysam-tagmanager', version='0.4',
11 | author='Taha Zerrouki',
12 | author_email='taha_zerrouki@hotmail.com',
13 | url='http://pypi.python.com/projects/mysam-tagmanager/',
14 | license='GPL',
15 | description="Mysam: Arabic tags manager",
16 | long_description_content_type='text/markdown',
17 | long_description = readme(),
18 | package_dir={'mysam': 'mysam'},
19 | packages=['mysam'],
20 | include_package_data=True,
21 | package_data = {
22 | 'mysam': ['doc/*.*','doc/html/*', "config/*"],
23 | },
24 | classifiers=[
25 | 'Development Status :: 5 - Production/Stable',
26 | 'Natural Language :: Arabic',
27 | 'Intended Audience :: Developers',
28 | 'Operating System :: OS Independent',
29 | 'Programming Language :: Python',
30 | 'Topic :: Text Processing :: Linguistic',
31 | ],
32 | );
33 |
34 |
--------------------------------------------------------------------------------
/tests/makedoc.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # makedoc.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import sys
26 | sys.path.append('../')
27 | sys.path.append('.')
28 | import mysam.tagconfig
29 | def main(args):
30 | import pandas as pd
31 | configuer = mysam.tagconfig.tagConfig()
32 | configuer.load_config()
33 | md = configuer.markdown_cat()
34 | print(md.encode('utf8'))
35 | mdc = configuer.markdown()
36 | print(mdc.encode('utf8'))
37 | mdm = configuer.markdown_map()
38 | print(mdm.encode('utf8'))
39 |
40 | if __name__ == '__main__':
41 | import sys
42 | sys.exit(main(sys.argv))
43 |
--------------------------------------------------------------------------------
/tests/readme_samples1.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # readme_samples1.py
5 | #
6 | # Copyright 2023 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import sys
25 | sys.path.append("../")
26 |
27 |
28 |
29 | import pandas as pd
30 |
31 | import mysam.tagconfig as tagconfig
32 | import mysam.tag_const as tag_const
33 |
34 | configuer = tagconfig.tagConfig()
35 | configuer.load_config()
36 | # display
37 | df = pd.DataFrame(configuer.tagsdict)
38 | print('****tagdict ****')
39 | print(df)
40 |
41 |
--------------------------------------------------------------------------------
/tests/readme_samples2.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # readme_samples1.py
5 | #
6 | # Copyright 2023 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import sys
25 | sys.path.append("../")
26 |
27 |
28 | import mysam.tagcoder
29 |
30 | taglists = [[u'اسم', u'هاء', u'مجرور',],
31 | u'تعريف::مرفوع:متحرك:ينون:::'.split(":"),
32 | ]
33 | tgcoder = mysam.tagcoder.tagCoder()
34 | for taglist in taglists:
35 | # encode
36 | tagcode = tgcoder.encode(taglist)
37 | print("tags list:", u";".join(taglist))
38 | print("tagcode:", tagcode)
39 | # decode a unifed tag string
40 | print("decode:", tgcoder.decode(tagcode))
41 |
42 |
--------------------------------------------------------------------------------
/tests/readme_samples3.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # readme_samples1.py
5 | #
6 | # Copyright 2023 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import sys
25 | sys.path.append("../")
26 |
27 | import mysam.taginflector
28 | tag_maker = mysam.taginflector.tagInflector()
29 | word = "يَسْتَعْمِلُونَهَا"
30 | tagcode = 'V-1;M3H-faU;W-H'
31 | print(tag_maker.inflect(tagcode))
32 |
--------------------------------------------------------------------------------
/tests/readme_samples4.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # readme_samples1.py
5 | #
6 | # Copyright 2023 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import sys
25 | sys.path.append("../")
26 |
27 |
28 |
29 | import mysam.tagcoder
30 | tag_coder = mysam.tagcoder.tagCoder()
31 | tagcode = 'V-0;M1H-faU;W--'
32 | tag = "ضمير متصل"
33 | print(tag_coder.add_tag(tag, tagcode))
34 |
35 | import mysam.tagcoder
36 | tag_coder = mysam.tagcoder.tagCoder()
37 | tagcode = 'V-0;M1H-faU;W-H'
38 | tag = "ضمير متصل"
39 | print(tag_coder.remove_tag(tag, tagcode))
40 |
--------------------------------------------------------------------------------
/tests/readme_samples5.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # readme_samples1.py
5 | #
6 | # Copyright 2023 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import sys
25 | sys.path.append("../")
26 |
27 |
28 |
29 |
30 | import mysam.tagcoder
31 | tag_coder = mysam.tagcoder.tagCoder()
32 | tags = ['اسم', 'مجرور', 'مذكر', "مفرد", "واو"]
33 | tagcode = tag_coder.encode(tags)
34 | print(tagcode)
35 | tag_search = u"مجرور"
36 | print(tag_coder.has_tag(tag_search, tagcode))
37 | tag_search = u"فعل"
38 | print(tag_coder.has_tag(tag_search, tagcode))
39 |
40 | # ~ import mysam.tagmaker
41 | # ~ tag_maker = mysam.tagmaker.tagMaker()
42 | # ~ tagcode = 'N--;--I----;---'
43 | # ~ tag_search = u"مجرور"
44 | # ~ print(tag_maker.has_tag(tag_search, tagcode))
45 |
46 |
--------------------------------------------------------------------------------
/tests/requirements:
--------------------------------------------------------------------------------
1 | pyarabic>=0.6.15
2 | pandas
3 | pytest
4 |
--------------------------------------------------------------------------------
/tests/tag.config:
--------------------------------------------------------------------------------
1 | #Part;Pos;Attribute;خاصية;code;Value;قيمة;inflection;
2 | # Word Type نوع الكلمة
3 | 1;1;word_type;نوع الكلمة;N;Noun;اسم;اسم;
4 | 1;1;word_type;نوع الكلمة;V;Verb;فعل;فعل;
5 | 1;1;word_type;نوع الكلمة;T;Tool;أداة;حرف;
6 | 1;1;word_type;نوع الكلمة;P;Punctuation;ترقيم;علامة ترقيم;
7 | 1;1;word_type;نوع الكلمة;S;Symbol;رمز;رمز;
8 | 1;1;word_type;نوع الكلمة;D;Numeric;عدد;عدد;
9 | 1;1;word_type;نوع الكلمة;-;Undef;لاشيء;;
10 | ## Sub Class صنف فرعي
11 | 1;2;subclass;صنف;M;Masdar;مصدر;;
12 | ## transitive
13 | 1;3;transitive;تعدي;0;intransitive;لازم;;
14 | 1;3;transitive;تعدي;1;transitive;متعدي;;
15 | 1;3;transitive;تعدي;2;double transitive;متعدي لمفعولين;;
16 | 1;3;transitive;تعدي;4;commun;مشترك;;
17 | 1;3;transitive;-;تعدي;undef;لاشيء;;
18 |
19 | # Conjugation
20 | ## Gender الجنس
21 | 2;1;gender;جنس;M;masculine;مذكر;مذكر
22 | 2;1;gender;جنس;F;Feminine;مؤنث;مؤنث;
23 | 2;1;gender;جنس;-;none;لاشيء;;
24 | ## Number العدد
25 | 2;2;number;عدد;1;single;مفرد;مفرد;
26 | 2;2;number;عدد;2;dual;مثنى;مثنى;
27 | 2;2;number;عدد;3;plural;جمع;جمع;
28 | 2;2;number;عدد;4;plural;جمع تكسير;جمع تكسير;
29 | 2;2;number;عدد;-;none;لاشيء;;
30 | ## Inlfection case الحالة الإعرابية
31 | 2;3;case;إعراب;U;marfou3;مرفوع;مرفوع;
32 | 2;3;case;إعراب;0;manjzoum; مجزوم;مجزوم;
33 | 2;3;case;إعراب;I;majrour;مجرور;مجرور;
34 | 2;3;case;إعراب;A;mansoub;منصوب;منصوب;
35 | 2;3;case;إعراب;B;mabni;مبني;مبني;
36 | 2;3;case;إعراب;-;undef;لاشيء;;
37 | ## Inflection marks
38 | 2;4;mark;علامة;u;damma;الضمة;الضمة;
39 | 2;4;mark;علامة;a;fatha;الفتحة;الفتحة;
40 | 2;4;mark;علامة;i;kasra;الكسرة;الكسرة;
41 | 2;4;mark;علامة;0;sukun;السكون;السكون;
42 | 2;4;mark;علامة;A;alef;الألف;الألف;
43 | 2;4;mark;علامة;W;waw;الواو;الواو;
44 | 2;4;mark;علامة;Y;yeh;الياء;الياء;
45 | 2;4;mark;علامة;N;noon;ثبوت النون;ثبوت النون;
46 | 2;4;mark;علامة;-;undef;لاشيء;;
47 |
48 |
49 | # Procletics and prefixes
50 | ## Conjuction
51 | 3;1;conjonction;عطف;W;WAW;الواو;;
52 | 3;1;conjonction;عطف;F;FEH;الفاء;;
53 | 3;1;conjonction;عطف;-;undef;لاشيء;;
54 | ## preposition
55 | 3;2;preposition;جر;B;Beh;باء;بالباء;
56 | 3;2;preposition;جر;K;Kaf;كاف;بالكاف;
57 | 3;2;preposition;جر;L;Lam;لام;باللام;
58 | 3;2;preposition;جر;-;undef;لاشيء;;
59 | ## Definition
60 | 3;3;definite;تعريف;L;definited;معرفة;;
61 | 3;3;definite;تعريف;-;indefinite;نكرة;;
62 |
63 |
64 | ## Enclitics
65 | 3;4;encletic;ضمير متصل;H;Heh;ضمير متصل;والضمير المتصل مبني;
66 | 3;4;encletic;ضمير متصل;-;undef;لاشيء;;
67 |
68 | # Special Verb
69 | ## Istiqbal
70 | 4;1;istqbal;استقبال;s;istqbal;استقبال;استقبال;
71 | 4;1;istqbal;استقبال;-;undef;لاشيء;;
72 | ## Voice البناء
73 | 4;2;voice;بناء;a;acive voice;معلوم;مبني للمعلوم;
74 | 4;2;voice;بناء;p;acive voice;مجهول;مبني للمجهول;
75 | 4;2;voice;بناء;-;undef;لاشيء;;
76 | ## tense الزمن
77 | 4;3;tense;زمن;p;past;ماض;ماضي;
78 | 4;3;tense;زمن;f;present;مضارع;مضارع;
79 | 4;3;tense;زمن;i;imperative;أمر;أمر;
80 | 4;3;tense;زمن;-;undef;لاشيء;;
81 | ## person الشخص
82 | 4;4;person;شخص;I;1st person;متكلم;;
83 | 4;4;person;شخص;Y;2nd person;مخاطب;;
84 | 4;4;person;شخص;H;3rd person;غائب;;
85 | 4;4;person;شخص;-;undef;لاشيء;;
86 |
87 | #Parameters: must starts by #PARAM:
88 | $PARAM:TAG_PARTS_SIZES=3;4;5;5
89 |
90 | $MAP:المضارع المعلوم=مضارع;معلوم;مرفوع
91 | $MAP:المضارع المجزوم=مضارع;معلوم;مجزوم
92 | $MAP:Noun=اسم
93 | $MAP:y=متعدي
94 | $MAP:الأمر المؤكد=أمر;مؤكذ
95 | $MAP:مضاف=ضمير متصل
96 | $MAP:الأمر=أمر
97 | $MAP:هن=غائب;مؤنث;جمع
98 | $MAP:هم=غائب;مذكر;جمع
99 | $MAP:هما=غائب;مذكر;مثنى
100 | $MAP:المضارع المجهول المنصوب=مضارع;مجهول;منصوب
101 | $MAP:المضارع المجهول المجزوم=مضارع;مجهول;مجزوم
102 | $MAP:مفعول به=ضمير متصل
103 | $MAP:n=لازم
104 | $MAP:هما مؤ=غائب;مؤنث;مثنى
105 | $MAP:هي=غائب;مؤنث;مفرد
106 | $MAP:المضارع المؤكد الثقيل المجهول =مضارع;مجهول;مؤكد
107 | $MAP:هو=غائب;مذكر;مفرد
108 | $MAP:أنتِ=مخاطب;مؤنث;مفرد
109 | $MAP:المضارع المنصوب=مضارع;معلوم;منصوب
110 | $MAP:أنت=مخاطب;مذكر;مفرد
111 | $MAP:الماضي المجهول=ماضي;مجهول
112 | $MAP:أنا=متكلم;مفرد
113 | $MAP:الماضي المعلوم=ماضي;معلوم
114 | $MAP:المضارع المؤكد الثقيل=مضارع;معلوم;مؤكد
115 | $MAP:أنتما مؤ=مخاطب;مؤنث;مثنى
116 | $MAP:المضارع المجهول=مضارع;مجهول;مرفوع
117 | $MAP:أنتما=مخاطب;مذكر;مثنى
118 | $MAP:Verb=فعل
119 | $MAP:أنتم=مخاطب;مذكر;جمع
120 | $MAP:تعريف=معرفة
121 | $MAP:أنتن=مخاطب;مؤنث;جمع
122 | $MAP:نحن=متكلم;جمع
123 |
124 |
--------------------------------------------------------------------------------
/tests/test_config.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # makedoc.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import sys
26 | sys.path.append('../')
27 | sys.path.append('.')
28 | import os
29 | import mysam.tag_const as tag_const
30 | import mysam.tagconfig as tagconfig
31 |
32 | import os
33 | def main(args):
34 | import pandas as pd
35 | configuer = tagconfig.tagConfig()
36 | file_conf = os.path.join( os.path.dirname(__file__), "config/tag.config")
37 | configuer.load_config(file_conf, debug=True)
38 | # display
39 | df = pd.DataFrame(tag_const.TAGSDICT)
40 | print('****tagdict ****')
41 | print(df)
42 | df2 = pd.DataFrame(tag_const.INVERSE_TAGSDICT)
43 | print('****inverse tagdict ****')
44 | print(df2)
45 | df3 = pd.DataFrame(tag_const.ATTR_TAGSDICT)
46 | print('****attr tagdict ****')
47 | print(df3)
48 | #~ df4 = pd.DataFrame(tag_const.TAGSMAP)
49 | print('****Tags MAP ****')
50 | #~ print(df4)
51 | for k in tag_const.TAGSMAP:
52 | line = u"#MAP:%s=%s"%(k, u';'.join(tag_const.TAGSMAP[k]))
53 | print(line.encode('utf8'))
54 | print('**** Structure ****')
55 | print(tag_const.TAG_PARTS_SIZES)
56 | print(configuer.tag_parts_sizes)
57 |
58 | if __name__ == '__main__':
59 | import sys
60 | sys.exit(main(sys.argv))
61 |
--------------------------------------------------------------------------------
/tests/test_maker.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # makedoc.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import sys
26 | sys.path.append('../mysam')
27 |
28 | import tagmaker
29 | import tagcoder
30 |
31 |
32 | def main(args):
33 |
34 | taglists = [[u'اسم', u'هاء', u'مجرور',],
35 | u'تعريف::مرفوع:متحرك:ينون:::'.split(":"),
36 | u'المضارع المعلوم:هو:::n:'.split(":"),
37 | u':مضاف:مجرور:متحرك:ينون:::'.split(':'),
38 | ]
39 | tag_maker = tagmaker.tagMaker()
40 | for taglist in taglists:
41 | #~ tag_maker = tagmaker.tagMaker("tag.config")
42 | tag_maker.reset()
43 | tag_maker._encode(taglist)
44 | print(u":".join(taglist))
45 | tagstr = str(tag_maker)
46 | print(tagstr)
47 | # decode a unifed tag string
48 | print(tag_maker._decode())
49 | print("****TagCoder****")
50 | tag_coder = tagcoder.tagCoder()
51 | for taglist in taglists:
52 | tagstr = tag_coder.encode(taglist)
53 | print(u":".join(taglist))
54 | print(tagstr)
55 | # decode a unifed tag string
56 | taglist_decoded = tag_coder.decode(tagstr)
57 | print(taglist_decoded)
58 | taglist_decoded = [y for (x,y) in taglist_decoded ]
59 | print(taglist_decoded)
60 | # test if error
61 | tagstr2 = tag_coder.encode(taglist_decoded)
62 | if tagstr2!= tagstr:
63 | print("error on decoding\n%s\n%s"%(tagstr, tagstr2))
64 | if __name__ == '__main__':
65 | import sys
66 | sys.exit(main(sys.argv))
67 |
--------------------------------------------------------------------------------
/tests/test_maker_readingtags.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # makedoc.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import sys
26 | sys.path.append('../')
27 | sys.path.append('.')
28 | import mysam.tagmaker as tagmaker
29 | import mysam.tag_const as tag_const
30 |
31 |
32 | def main(args):
33 | import pandas as pd
34 | # test all existing tags
35 | tag_maker = tagmaker.tagMaker()
36 | tagstr = str(tag_maker)
37 | print("----")
38 | for tag in tag_const.TAGSDICT:
39 | tagstr = str(tag_maker)
40 | tag_maker.add(tag)
41 | tagstr_new = str(tag_maker)
42 | if tagstr == tagstr_new:
43 | print(u" ".join(["error:old\t", tagstr, tag, "\n new:\t", tagstr_new]).encode('utf8'))
44 | else:
45 | print(u" ".join([tag, tagstr_new]).encode('utf8'))
46 | decode_tags = tag_maker.decode()
47 | df = pd.DataFrame(decode_tags)
48 | print(df)
49 | tag_maker.add(u"اسم")
50 | print("******Inflect", tag_maker.inflect().encode('utf8'))
51 | tag_maker.add(u"فعل")
52 | print("***Verb***Inflect", tag_maker.inflect().encode('utf8'))
53 |
54 |
55 |
56 |
57 | if __name__ == '__main__':
58 | import sys
59 | sys.exit(main(sys.argv))
60 |
--------------------------------------------------------------------------------
/tests/test_mytager.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # test_mytager.py
5 | #
6 | # Copyright 2020 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import mysam.tagmaker
25 |
26 |
27 | llist = [
28 | [u'اسم', u'مضير متصل', u'مجرور'],
29 | ['الماضي المعلوم', 'هو', 'n', ''],
30 | ['تعريف', 'مرفوع', 'متحرك', 'ينون', '', ''],
31 | ['', '', '', 'حرف', 'تعليل', 'مبني', 'ناصب', ''],
32 | ['المضارع المعلوم', 'هو', 'n', ''],
33 | ['نقطة', 'break', '', ''],
34 | ]
35 | def test():
36 | #~ mytagmaker = mysam.tagmaker.tagMaker("tag.config")
37 | mytagmaker = mysam.tagmaker.tagMaker()
38 | for ll in llist:
39 | mytagmaker.reset()
40 | mytagmaker.encode(ll)
41 | print(ll)
42 | inflect = u"[%s]{%s}" % (str(mytagmaker), mytagmaker.inflect()) + " "
43 | print(inflect)
44 |
45 |
46 | if __name__ == '__main__':
47 | test()
48 |
--------------------------------------------------------------------------------
/tests/test_samples.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # makedoc.py
5 | #
6 | # Copyright 2018 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 |
25 | import sys
26 | sys.path.append('../')
27 | sys.path.append('.')
28 |
29 | def main(args):
30 | # exmpale for encode
31 | import mysam.tagmaker as tagmaker
32 | tag_maker = tagmaker.tagMaker()
33 | taglist = [u'اسم', u'مضير متصل', u'مجرور']
34 | tag_maker.encode(taglist)
35 | tagstr = str(tag_maker)
36 | print(tagstr.encode('utf8'))
37 |
38 |
39 | # exmaple for decode
40 | print("***exmaple for decode***")
41 | tag_maker = tagmaker.tagMaker()
42 | tagcode = 'N--;--I-;----;---'
43 | print(tag_maker.repr(tag_maker.decode(tagcode)).encode('utf8'))
44 |
45 | print("***exmaple for inflect***")
46 | tag_maker = tagmaker.tagMaker()
47 | tagcode = 'N--;M3IY;---H;---'
48 | print(tag_maker.inflect(tagcode).encode('utf8'))
49 |
50 | print("***exmaple for add tag***")
51 | tag_maker = tagmaker.tagMaker()
52 | tagcode = 'N--;--I-;----;---'
53 | tag_new = u"تعريف"
54 | tag_maker.add(tag_new)
55 | tag_new = u"اسم"
56 | tag_maker.add(tag_new)
57 | print(str(tag_maker).encode('utf8'))
58 |
59 | print("***exmaple for has tag***")
60 | tag_maker = tagmaker.tagMaker()
61 | tagcode = 'N--;--I-;----;---'
62 | tag_search = u"مجرور"
63 | print(tag_maker.has_tag(tag_search, tagcode))
64 |
65 |
66 | if __name__ == '__main__':
67 | import sys
68 | sys.exit(main(sys.argv))
69 |
--------------------------------------------------------------------------------
/tests/test_unit_tagcoder.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # test_unit_coder.py
5 | #
6 | # Copyright 2023 zerrouki
7 | #
8 | # This program is free software; you can redistribute it and/or modify
9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation; either version 2 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program; if not, write to the Free Software
20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 | # MA 02110-1301, USA.
22 | #
23 | #
24 | import unittest
25 | import sys
26 | import pprint
27 | # check if list are identical
28 | # using collections.Counter()
29 | import collections
30 | import pyarabic.araby as araby
31 |
32 | sys.path.append('../')
33 | import mysam.tagcoder
34 | import mysam.taginflector
35 |
36 |
37 |
38 | from fixtures import tagcode_dataset
39 |
40 |
41 | class tagCoderTestCase(unittest.TestCase):
42 | """Tests for `Lemmatizer`."""
43 |
44 | def setUp(self):
45 | """
46 | initial lemmatizer
47 | """
48 | self.word_lemma_list= tagcode_dataset.Lemmas_DataSet
49 | self.limit = 1000
50 | self.mytagcoder = mysam.tagcoder.tagCoder()
51 | self.inflector = mysam.taginflector.tagInflector()
52 |
53 |
54 | def test_word_cases(self, ):
55 | """ test word case"""
56 | # ~ word = "وفي"
57 | # ~ expected_tagcode = 'V-1;F1Y-i--;---'
58 | # ~ tagscode_list = self._check_word_tags(word)
59 | # ~ print(tagscode_list)
60 | # ~ self.assertIn(expected_tagcode, tagscode_list)
61 |
62 | # ~ word = "بالمدرستين"
63 | # ~ expected_tagcode = 'NA-;F2----I;-BL'
64 | # ~ tagscode_list = self._check_word_tags(word)
65 | # ~ print(tagscode_list)
66 | # ~ self.assertIn(expected_tagcode, tagscode_list)
67 |
68 | word = "واحتاج"
69 | expected_tagcode = 'V-0;M1H-paB;W--'
70 | expected_inflect = "فعل ماض مبني على الفتح الظاهر على آخره"
71 | tags = ['الماضي المعلوم', 'هو', 'n',"مبني", 'Verb', "معطوف بالواو"]
72 | # ~ expected_tagcode = ''
73 | tagscode = self.mytagcoder.encode(tags)
74 | inflect = self.inflector.inflect(tagscode)
75 | print(word, tagscode, inflect)
76 |
77 | self.assertEqual(expected_tagcode, tagscode, "Error on tagscode")
78 | self.assertEqual(expected_inflect, inflect, "Error on Inflection")
79 |
80 | def test_get_mark_cases(self, ):
81 | """ test word case"""
82 |
83 | tagscode = 'V-0;M1H-paB;W--'
84 | expected_inflect = "فعل ماض مبني على الفتح الظاهر على آخره"
85 | tags = ['الماضي المعلوم', 'هو', 'n',"مبني", 'Verb', "معطوف بالواو"]
86 | # ~ expected_tagcode = ''
87 | inflect = self.inflector._get_verb_mark(tagscode)
88 | self.assertEqual(expected_inflect, inflect, "Error on Inflection")
89 |
90 |
91 | def test_word_inflect(self, ):
92 | """ test word case"""
93 | word = "ويحتاج"
94 | tagscode = 'V-0;M1H-faU;W--'
95 | expected_inflect = "فعل مضارع مرفوع وعلامة رفعه الضمة الظاهرة على آخره"
96 | inflect = self.inflector.inflect(tagscode)
97 | self.assertEqual(expected_inflect, inflect, "Error on Inflection")
98 |
99 | word = "ويحتاجه"
100 | tagscode = 'V-0;M1H-faU;W-H'
101 | expected_inflect = "فعل مضارع مرفوع وعلامة رفعه الضمة الظاهرة على آخره والضمير المتصل مبني في محل نصب مفعول به"
102 | inflect = self.inflector.inflect(tagscode)
103 | self.assertEqual(expected_inflect, inflect, "Error on Inflection")
104 |
105 | word = "ويحتاجانها"
106 | tagscode = 'V-0;M2H-faU;W-H'
107 | expected_inflect = "فعل مضارع مرفوع وعلامة رفعه ثبوت النون لأنه من الأفعال الخمسة وألف الاثنين: ضمير متصل مبني في محل رفع فاعل والضمير المتصل مبني في محل نصب مفعول به"
108 | inflect = self.inflector.inflect(tagscode)
109 | self.assertEqual(expected_inflect, inflect, "Error on Inflection")
110 |
111 | def test_word_addtag(self, ):
112 | """ test word case"""
113 | word = "ويحتاج"
114 | tagscode = 'V-0;M1H-faU;W--'
115 | expected_tagscode = 'V-0;M1H-faU;W-H'
116 | new_tagscode = self.mytagcoder.add_tag("ضمير متصل", tagscode)
117 | self.assertEqual(expected_tagscode, new_tagscode, "Error on adding tag")
118 |
119 | tagscode = 'V-0;M1H-faU;W-H'
120 | expected_tagscode = 'V-0;M1H-faU;W--'
121 | new_tagscode = self.mytagcoder.remove_tag("ضمير متصل", tagscode)
122 | self.assertEqual(expected_tagscode, new_tagscode, "Error on adding tag")
123 |
124 |
125 | if __name__ == '__main__':
126 | unittest.main()
127 |
--------------------------------------------------------------------------------