5 | * Distributed under EPL/LGPL/GPL/AL/BSD multi-license.
6 | */
7 |
8 | package wiwordik.word_card;
9 |
10 | import wikokit.base.wikt.sql.TMeaning;
11 | import wikokit.base.wikipedia.sql.Connect;
12 | import wikokit.base.wikt.sql.quote.TQuote;
13 |
14 | import javafx.scene.layout.VBox;
15 | import java.lang.*;
16 |
17 | /** One WCQuote contains all quotes (phrase/sentences) that illustrates one meaning
18 | * of Wiktionary word.
19 | *
20 | * @see wikt.word.WQuote
21 | */
22 | public class WCQuote {
23 |
24 | public VBox group = new VBox();
25 |
26 | /** Creates a part of card (parts of wiki pages) with list of quotes
27 | * related to one meaning (sense).
28 | *
29 | * @return true if there are any quotes for this meaning.
30 | **/
31 | public boolean create ( Connect conn,
32 | TMeaning _tmeaning
33 | )
34 | {
35 | group.setSpacing(5);
36 |
37 | // def rels : TRelation[] = TRelation.get(conn, _tmeaning);
38 | TQuote[] quotes = TQuote.get(conn, _tmeaning);
39 | if (quotes.length == 0)
40 | return false;
41 |
42 | String list;
43 | for(TQuote q : quotes) {
44 | // list = "{list}{q.getText()} || ";
45 |
46 | WCQuoteOneSentence _1quote = new WCQuoteOneSentence();
47 | _1quote.create(conn, q);
48 |
49 | // only visual part, skip logic
50 | group.getChildren().addAll(_1quote.group);
51 | }
52 |
53 | return true;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/android/common_wiki_android/src/wikokit/base/wikt/db/Decompressor.java:
--------------------------------------------------------------------------------
1 | package wikokit.base.wikt.db;
2 |
3 | import android.util.Log;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileOutputStream;
7 | import java.util.zip.ZipEntry;
8 | import java.util.zip.ZipInputStream;
9 |
10 | /** Decompress ziped file.
11 | *
12 | * @see http://www.jondev.net/articles/Unzipping_Files_with_Android_%28Programmatically%29
13 | */
14 | public class Decompressor {
15 | private String _zipFile;
16 | private String _location;
17 |
18 | public Decompressor(String zipFile, String location) {
19 | _zipFile = zipFile;
20 | _location = location;
21 |
22 | _dirChecker("");
23 | }
24 |
25 | public void unzip() {
26 | try {
27 | FileInputStream fin = new FileInputStream(_zipFile);
28 | ZipInputStream zin = new ZipInputStream(fin);
29 | ZipEntry ze = null;
30 | while ((ze = zin.getNextEntry()) != null) {
31 | Log.v("Decompress", "Unzipping " + ze.getName());
32 |
33 | if(ze.isDirectory()) {
34 | _dirChecker(ze.getName());
35 | } else {
36 | FileOutputStream fout = new FileOutputStream(_location + ze.getName());
37 | for (int c = zin.read(); c != -1; c = zin.read()) {
38 | fout.write(c);
39 | }
40 |
41 | zin.closeEntry();
42 | fout.close();
43 | }
44 |
45 | }
46 | zin.close();
47 | } catch(Exception e) {
48 | Log.e("Decompress", "unzip", e);
49 | }
50 |
51 | }
52 |
53 | private void _dirChecker(String dir) {
54 | File f = new File(_location + dir);
55 |
56 | if(!f.isDirectory()) {
57 | f.mkdirs();
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/jcfd/test/net/zuckerfrei/jcfd/MockBufferedReader.java:
--------------------------------------------------------------------------------
1 | package net.zuckerfrei.jcfd;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.Reader;
6 | import java.io.StringReader;
7 |
8 |
9 | /**
10 | * DOCUMENT ME!
11 | *
12 | * @author Davor Cengija
13 | * @version $Revision: 1.1.1.1 $
14 | */
15 | public class MockBufferedReader
16 | extends BufferedReader
17 | {
18 |
19 | //~ Instance variables ====================================================
20 |
21 | /**
22 | * DOCUMENT ME!
23 | */
24 | public String[] content;
25 |
26 | /**
27 | * DOCUMENT ME!
28 | */
29 | public int position = 0;
30 |
31 | /**
32 | * DOCUMENT ME!
33 | */
34 | public int readLineCount = 0;
35 |
36 | //~ Constructors ==========================================================
37 |
38 | /**
39 | * Constructor for MockBufferedReader.
40 | *
41 | * @param in
42 | * @param sz
43 | */
44 | public MockBufferedReader(Reader in, int sz) {
45 | super(in, sz);
46 | }
47 |
48 |
49 | /**
50 | * Constructor for MockBufferedReader.
51 | *
52 | * @param in
53 | */
54 | public MockBufferedReader(Reader in) {
55 | super(new StringReader("mock"));
56 | }
57 |
58 | //~ Methods ===============================================================
59 |
60 | /**
61 | * DOCUMENT ME!
62 | *
63 | * @param content DOCUMENT ME!
64 | */
65 | public void setContent(String[] content) {
66 | this.content = content;
67 | }
68 |
69 |
70 | /**
71 | * @see java.io.BufferedReader#readLine()
72 | */
73 | public String readLine()
74 | throws IOException
75 | {
76 | readLineCount++;
77 | return content[position++];
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/android/kiwidict/res/layout/word_card_language.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
18 |
19 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
36 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/piwidict/lib/header.php:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | piwidict - PHP framework to work with Wiktionary parsed database
7 |
8 |
14 |
15 |
22 |
23 |
30 |
31 |
32 | NB!
33 | Attention: beta-testing mode
34 |
35 | "; // debug
37 | // print "Session _user_password = ".$_SESSION['_user_password']."
";
38 |
39 | ?>
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sql_procedures/hyponyms/hyponyms_test.sql:
--------------------------------------------------------------------------------
1 | == test enwiki ==
2 | CALL hyponyms('Network_flow')//
3 |
4 | == test simplewiki ==
5 | INSERT INTO cat_count (page_id,page_title) (SELECT page_id,page_title FROM page WHERE page_namespace=14 AND (page_title='Websites' OR page_title='Wikimedia' OR page_title='Wikis'));
6 | INSERT INTO cat_count (page_id,page_title) (SELECT page_id,page_title FROM page WHERE page_namespace=14 AND (page_title='Websites' OR page_title='Wikimedia' OR page_title='Wikis' OR page_title='Internet'));
7 |
8 | INSERT INTO cat_count (page_id,page_title) (SELECT page_id,page_title FROM page WHERE page_namespace=14 AND (page_title='Kings_of_Urartu' OR page_title='Monarchs_of_Armenia'));
9 |
10 | UPDATE cat_count SET n_depth=1 WHERE page_id=5498;
11 |
12 | -- test 1: Computer and Keyboard --
13 | -- Computers Computer_science Computing Writing_tools Tools
14 | Category:Everyday life -> Architecture -> Construction -> Tools
15 | Category:Everyday life -> Tools
16 |
17 | Category:Everyday life -> Learning -> Skills -> Tools
18 | Category:Everyday life -> Tools
19 |
20 | 1.
21 | DELETE FROM cat_count//
22 | 2.
23 | INSERT INTO cat_count (page_id,page_title) (SELECT page_id,page_title FROM page WHERE page_namespace=14 AND page_title IN ('Computers', 'Computer_science', 'Computing', 'Writing_tools', 'Tools', 'Appliances', 'Skills'))//
24 | 3.
25 | CALL hyponyms('Writing_tools')//
26 | CALL hyponyms('Tools')//
27 | CALL hyponyms('Skills')//
28 | CALL hyponyms('Learning')//
29 | CALL hyponyms('Everyday_life')//
30 |
31 | CALL hyponyms('Main_page')//
32 |
33 | 4.
34 | SELECT * FROM cat_count WHERE page_title IN ('Computers', 'Computer_science', 'Computing', 'Writing_tools', 'Tools', 'Appliances', 'Skills')//
35 | SELECT * FROM cat_count WHERE page_title IN ('Computers', 'Computer_science', 'Computing', 'Writing_tools', 'Tools', 'Appliances', 'Skills', 'Learning') ORDER BY n_hyponyms DESC//
36 |
--------------------------------------------------------------------------------
/wiwordik/jnlp/wiwordik-en.jnlp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | wiwordik-en
6 | Andrew Krizhanovsky
7 |
8 | Machine-readable Wiktionary (visualization of the parsed English Wiktionary database
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/wiwordik/jnlp/wiwordik-ru_test.jnlp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | wiwordik-ru_test
7 | Andrew Krizhanovsky
8 |
9 | Machine-readable Wiktionary (visualization of the parsed Russian Wiktionary database).
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/common_wiki/src/wikokit/base/wikt/multi/ru/WRedirectRu.java:
--------------------------------------------------------------------------------
1 | /* WRedirectRu.java - functions related to redirects in wiki and Russian Wiktionary.
2 | *
3 | * Copyright (c) 2009 Andrew Krizhanovsky
4 | * Distributed under GNU General Public License.
5 | */
6 |
7 | package wikokit.base.wikt.multi.ru;
8 |
9 | import java.util.regex.Pattern;
10 | import java.util.regex.Matcher;
11 |
12 | /** Redirect related functions in wiki and Russian Wiktionary.
13 | *
14 | * @see http://ru.wiktionary.org/wiki/Викисловарь:Перенаправления
15 | */
16 | public class WRedirectRu {
17 |
18 | /** Gets target page of the redirect, extracts [[pagename]] from double brackets. */
19 | private final static Pattern ptrn_redirect = Pattern.compile(
20 | "#(REDIRECT|ПЕРЕНАПРАВЛЕНИЕ) \\[\\[(.+?)\\]\\]",
21 | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
22 |
23 | /** Checks whether this is a redirect page. If this is true then
24 | * the title of the target (redirected) page will be returned.
25 | *
26 | * @param wikt_lang language of Wiktionary
27 | * @param page_title word which are described in this article
28 | * @param text defines source wiki text
29 | * @return if this is not a redirect then return null
30 | */
31 | public static String getRedirect(String page_title,
32 | StringBuffer text) {
33 |
34 | // #REDIRECT [[pagename]] (or #redirect [[pagename]]
35 | // or #ПЕРЕНАПРАВЛЕНИЕ [[pagename]]
36 |
37 | //int len = "#REDIRECT [[".length(); // == 12
38 | if(text.length() < 12 || text.charAt(0) != '#')
39 | return null;
40 |
41 | Matcher m = ptrn_redirect.matcher(text);
42 | if (m.find()){
43 | return m.group(2);
44 | }
45 |
46 | return null;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/common_wiki/src/wikokit/base/wikt/word/WRedirect.java:
--------------------------------------------------------------------------------
1 | /* WRedirect.java - functions related to redirects in wiki and Wiktionary.
2 | *
3 | * Copyright (c) 2009 Andrew Krizhanovsky
4 | * Distributed under GNU General Public License.
5 | */
6 |
7 | package wikokit.base.wikt.word;
8 |
9 | import wikokit.base.wikipedia.language.LanguageType;
10 |
11 | import wikokit.base.wikt.multi.ru.WRedirectRu;
12 | import wikokit.base.wikt.multi.en.WRedirectEn;
13 |
14 | /** Redirect related functions in wiki and Wiktionary.
15 | */
16 | public class WRedirect {
17 |
18 | /** Checks whether this is a redirect page. If this is true then
19 | * the title of the target (redirected) page will be returned.
20 | *
21 | * @param wikt_lang language of Wiktionary
22 | * @param page_title word which are described in this article
23 | * @param text defines source wiki text
24 | * @return if this is not a redirect then return null
25 | */
26 | public static String getRedirect(LanguageType wikt_lang,
27 | String page_title,
28 | StringBuffer text) {
29 |
30 | // #ПЕРЕНАПРАВЛЕНИЕ [[нелётный]]
31 | // #REDIRECT [[burn one's fingers]]
32 |
33 | LanguageType l = wikt_lang;
34 | String redirect_dest = null;
35 |
36 | if(l == LanguageType.ru) {
37 | redirect_dest = WRedirectRu.getRedirect(page_title, text);
38 | } else if(l == LanguageType.en) {
39 | redirect_dest = WRedirectEn.getRedirect(page_title, text);
40 | //} else if(code.equalsIgnoreCase( "simple" )) {
41 | // return WordSimple;
42 |
43 | // todo
44 | // ...
45 |
46 | } else {
47 | throw new NullPointerException("Null LanguageType");
48 | }
49 |
50 |
51 | return redirect_dest;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/common_wiki/src/wikokit/base/wikt/multi/ru/quote/TitleAndWikilink.java:
--------------------------------------------------------------------------------
1 | /* TitleAndWikilink.java - corresponds to the (wikified) title
2 | * of quote phrase/sentence that illustrates a meaning of a word in Russian Wiktionary.
3 | *
4 | * Copyright (c) 2012 Andrew Krizhanovsky
5 | * Distributed under EPL/LGPL/GPL/AL/BSD multi-license.
6 | */
7 | package wikokit.base.wikt.multi.ru.quote;
8 |
9 | /** (Wikified) title of quote phrase / sentence.
10 | */
11 | public class TitleAndWikilink {
12 | public TitleAndWikilink() {
13 | title = "";
14 | title_wikilink = "";
15 | }
16 |
17 | /** Title of the work. */
18 | public String title;
19 |
20 | /** Link to a book in Wikipedia (format: [[s:title|]] or [[:s:title|]]). */
21 | public String title_wikilink;
22 |
23 |
24 | /** Parses text (e.g. "[[:s:У окна (Андреев)|У окна]]") into
25 | * title_wikilink "У окна (Андреев)" and title "У окна".
26 | */
27 | public void parseTitle(String text) {
28 |
29 | // replace " " by " "
30 | if(text.contains(" "))
31 | text = text.replace(" ", " ");
32 |
33 | title = text; // first version
34 | if(!(text.startsWith("[[:s:") ||
35 | text.startsWith("[[s:")) ||
36 | !text.endsWith("]]") ||
37 | !text.contains("|"))
38 | return;
39 |
40 | if(text.startsWith("[[:s:"))
41 | text = text.substring(5, text.length() - 2); // "[[:s:" . text . "]]"
42 | else
43 | text = text.substring(4, text.length() - 2); // "[[s:" . text . "]]"
44 |
45 | // split by |
46 | // [[:s:The title|The title]]
47 | int pos = text.indexOf("|");
48 | if(-1 == pos)
49 | return;
50 |
51 | title_wikilink = text.substring(0, pos);
52 | title = text.substring(pos + 1);
53 | }
54 | }
--------------------------------------------------------------------------------
/sql_procedures/hyponyms/cat_count.sql:
--------------------------------------------------------------------------------
1 | DELIMITER //
2 | DROP TABLE IF EXISTS cat_count;//
3 | CREATE TABLE cat_count (
4 | `page_id` INT(10) UNSIGNED NOT NULL COMMENT 'Category page identifier. Corresponds to page.page_id',
5 | `page_title` VARCHAR(255) NOT NULL COMMENT 'Category page title. Copy of page.page_title, see http://www.mediawiki.org/wiki/Page_table',
6 | `n_depth` TINYINT UNSIGNED NOT NULL COMMENT 'The depth of a node n is the length of the path from the root to the node. The root node is at depth zero.',
7 | `n_subcat` SMALLINT UNSIGNED NOT NULL COMMENT 'Number of direct sub-categories (childrens). It is zero for category-leaf.',
8 | `n_articles` MEDIUMINT UNSIGNED NOT NULL COMMENT 'Number of articles which have this category.',
9 |
10 | `n_hyponyms` MEDIUMINT UNSIGNED NOT NULL COMMENT 'n_subcat + n_articles + n_hyponyms_of_sub-categories',
11 | `ic` FLOAT NOT NULL DEFAULT -1 COMMENT 'Infromation content, -1 helps to avoid additional categories which are not covered by root category',
12 | UNIQUE KEY `page_id` (`page_id`),
13 | UNIQUE KEY `page_title` (`page_title`)
14 | )
15 | ENGINE = MYISAM
16 | COMMENT = 'Category hyponyms counter';//
17 |
18 |
19 | DROP TABLE IF EXISTS cat_parent_stack;//
20 | CREATE TABLE cat_parent_stack (
21 | `page_title` VARCHAR(255) NOT NULL COMMENT 'Copy of page.page_title, see http://www.mediawiki.org/wiki/Page_table',
22 | `n_depth` TINYINT UNSIGNED NOT NULL COMMENT 'The depth of a node n is the length of the path from the root to the node. The root node is at depth zero.',
23 | UNIQUE KEY `page_title` (`page_title`)
24 | )
25 | ENGINE = MYISAM
26 | COMMENT = 'Temporary table of categories from root to current category. It is used to skip cycles of categories.';//
27 |
28 |
29 | DROP TABLE IF EXISTS cat_cycles;//
30 | CREATE TABLE cat_cycles (
31 | `concat_titles` VARCHAR(255) NOT NULL COMMENT 'List of category titles which forms a cycle'
32 | )
33 | ENGINE = MYISAM
34 | COMMENT = 'List of categories which forms cycles.';//
35 |
--------------------------------------------------------------------------------
/hits_wiki/test/wikipedia/sql_idf/PageTest.java:
--------------------------------------------------------------------------------
1 |
2 | package wikipedia.sql_idf;
3 |
4 | import wikipedia.sql.Connect;
5 |
6 | import java.sql.Connection;
7 | import java.util.*;
8 | import junit.framework.TestCase;
9 |
10 | public class PageTest extends TestCase {
11 |
12 | public Connect idfruwiki_conn;
13 | public Connect idfsimplewiki_conn;
14 |
15 | public List tp_list1, tp_list2;
16 | Term t1, t2;
17 | String lemma1, lemma2;
18 |
19 | public PageTest(String testName) {
20 | super(testName);
21 | }
22 |
23 | @Override
24 | protected void setUp() throws Exception {
25 | super.setUp();
26 |
27 | idfruwiki_conn = new Connect();
28 | idfruwiki_conn.Open(Connect.IDF_RU_HOST, Connect.IDF_RU_DB, Connect.IDF_RU_USER, Connect.IDF_RU_PASS);
29 |
30 | idfsimplewiki_conn = new Connect();
31 | idfsimplewiki_conn.Open(Connect.IDF_SIMPLE_HOST, Connect.IDF_SIMPLE_DB, Connect.IDF_SIMPLE_USER, Connect.IDF_SIMPLE_PASS);
32 |
33 | java.sql.Connection conn = idfsimplewiki_conn.conn;
34 | lemma1 = "GREEN";
35 | lemma2 = "TEA";
36 | t1 = Term.get(conn, lemma1);
37 | t2 = Term.get(conn, lemma2);
38 | tp_list1 = TermPage.getPagesByTermID(conn, t1);
39 | tp_list2 = TermPage.getPagesByTermID(conn, t2);
40 | }
41 |
42 | @Override
43 | protected void tearDown() throws Exception {
44 | super.tearDown();
45 | }
46 |
47 | /**
48 | * Test of fillPages method, of class Page.
49 | */
50 | public void testFillPages_simple() {
51 | System.out.println("fillPages_simple");
52 | java.sql.Connection conn = idfsimplewiki_conn.conn;
53 |
54 | Page.fillPages(conn, tp_list1);
55 | Page.fillPages(conn, tp_list2);
56 |
57 | List intersection = TermPage.intersectPageTitles(tp_list1, tp_list2);
58 | assertTrue(intersection.size() > 0);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/android/common_wiki_android/src/wikokit/base/wikipedia/sql/UtilSQL.java:
--------------------------------------------------------------------------------
1 |
2 | package wikipedia.sql;
3 |
4 | import java.sql.*;
5 |
6 | /** Misc SQL routines.
7 | */
8 | public class UtilSQL {
9 |
10 | /** Deletes all records from the table 'table_name', resets auto increment.
11 | *
12 | * DELETE FROM table_name;
13 | * ALTER TABLE table_name AUTO_INCREMENT = 0;
14 | */
15 | public static void deleteAllRecordsResetAutoIncrement (Connect connect, String table_name) {
16 |
17 | Statement s = null;
18 | ResultSet rs= null;
19 |
20 | try {
21 | s = connect.conn.createStatement ();
22 | s.addBatch("DELETE FROM "+ table_name +";");
23 | s.addBatch("ALTER TABLE "+ table_name +" AUTO_INCREMENT = 1;");
24 | s.executeBatch();
25 |
26 | } catch(SQLException ex) {
27 | System.err.println("SQLException (wikipedia.sql UtilSQL.java deleteAllRecordsResetAutoIncrement()):: table = "+ table_name +"; msg = " + ex.getMessage());
28 | } finally {
29 | if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { } rs = null; }
30 | if (s != null) { try { s.close(); } catch (SQLException sqlEx) { } s = null; }
31 | }
32 | }
33 |
34 |
35 | public static void dropTable (Connect connect, String table_name)
36 | {
37 | if(null == connect)
38 | return;
39 |
40 | StringBuffer str_sql = new StringBuffer();
41 | try {
42 | Statement s = connect.conn.createStatement ();
43 | try {
44 | str_sql.append("DROP TABLE IF EXISTS `"+ table_name + "`");
45 | s.execute(str_sql.toString());
46 | } finally {
47 | s.close();
48 | }
49 | } catch(SQLException ex) {
50 | System.err.println("SQLException (MSRMeanSemrelXX.dropTable()): sql='" + str_sql + "' " + ex.getMessage());
51 | }
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/common_wiki_jdbc/src/wikokit/base/wikipedia/sql/UtilSQL.java:
--------------------------------------------------------------------------------
1 |
2 | package wikokit.base.wikipedia.sql;
3 |
4 | import java.sql.*;
5 |
6 | /** Misc SQL routines.
7 | */
8 | public class UtilSQL {
9 |
10 | /** Deletes all records from the table 'table_name', resets auto increment.
11 | *
12 | * DELETE FROM table_name;
13 | * ALTER TABLE table_name AUTO_INCREMENT = 1;
14 | */
15 | public static void deleteAllRecordsResetAutoIncrement (Connect connect, String table_name) {
16 |
17 | Statement s = null;
18 | ResultSet rs= null;
19 |
20 | try {
21 | s = connect.conn.createStatement ();
22 | s.addBatch("DELETE FROM "+ table_name +";");
23 | s.addBatch("ALTER TABLE "+ table_name +" AUTO_INCREMENT = 1;");
24 | s.executeBatch();
25 |
26 | } catch(SQLException ex) {
27 | System.out.println("SQLException (wikipedia.sql UtilSQL.java deleteAllRecordsResetAutoIncrement()):: table = "+ table_name +"; msg = " + ex.getMessage());
28 | } finally {
29 | if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { } rs = null; }
30 | if (s != null) { try { s.close(); } catch (SQLException sqlEx) { } s = null; }
31 | }
32 | }
33 |
34 |
35 | public static void dropTable (Connect connect, String table_name)
36 | {
37 | if(null == connect)
38 | return;
39 |
40 | StringBuffer str_sql = new StringBuffer();
41 | try {
42 | Statement s = connect.conn.createStatement ();
43 | try {
44 | str_sql.append("DROP TABLE IF EXISTS `"+ table_name + "`");
45 | s.execute(str_sql.toString());
46 | } finally {
47 | s.close();
48 | }
49 | } catch(SQLException ex) {
50 | System.out.println("SQLException (MSRMeanSemrelXX.dropTable()): sql='" + str_sql + "' " + ex.getMessage());
51 | }
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/common_wiki/src/wikokit/base/wikt/constant/SoftRedirectType.java:
--------------------------------------------------------------------------------
1 | /* SoftRedirectType.java - list of types of soft redirects used in all wiktionaries.
2 | *
3 | * Copyright (c) 2009 Andrew Krizhanovsky
4 | * Distributed under GNU General Public License.
5 | */
6 |
7 | package wikokit.base.wikt.constant;
8 |
9 | import java.util.Map;
10 | import java.util.HashMap;
11 |
12 | /** Names of types of soft redirects used in all wiktionaries.
13 | *
14 | * @see Wiktionary:Redirections and Help:Redirect in English Wiktionary
15 | * @see TPage.is_redirect - a hard redirect.
16 | */
17 | public class SoftRedirectType {
18 |
19 | /** Name of a redirect type, e.g. SpellingError */
20 | private final String name;
21 |
22 | @Override
23 | public String toString() { return name; }
24 |
25 | /* Set helps to check the presence of elements */
26 | private static Map name2type = new HashMap();
27 |
28 | private SoftRedirectType (String _name) {
29 | name = _name;
30 | name2type.put(_name, this);
31 | }
32 |
33 | /** Checks weather exists the type by its name. */
34 | public static boolean has(String _name) {
35 | return name2type.containsKey(_name);
36 | }
37 |
38 | /** Gets a type by its name */
39 | public static SoftRedirectType get(String _name) {
40 | return name2type.get(_name);
41 | }
42 |
43 |
44 | /** The types of soft redirects are: */
45 | /*************************************/
46 |
47 | /** It's not a redirect, it is the usual Wiktionary entry */
48 | public static final SoftRedirectType None = new SoftRedirectType("None");
49 |
50 | /** Wordform - soft redirect to correct spelling. */
51 | public static final SoftRedirectType Wordform = new SoftRedirectType("Wordform");
52 |
53 | /** Misspelling - soft redirect to correct spelling {{misspelling of|}} or {{wrongname|}}. */
54 | public static final SoftRedirectType Misspelling = new SoftRedirectType("Misspelling");
55 | }
56 |
--------------------------------------------------------------------------------
/common_wiki/src/wikokit/base/wikt/constant/Image.java:
--------------------------------------------------------------------------------
1 | /* Image.java - picture in the Wiktionary entry related to some meaning of word,
2 | * filename and picture caption are contained in [[File:...]] or {{илл|}}.
3 | *
4 | * Copyright (c) 2017 Andrew Krizhanovsky
5 | * Distributed under EPL/LGPL/GPL/AL/BSD multi-license.
6 | */
7 | package wikokit.base.wikt.constant;
8 |
9 | /** Image (picture) related to some definition (meaning).
10 | *
11 | * Filenames and captions of images could be presented in Wiktionary entry.
12 | */
13 | public class Image {
14 |
15 |
16 | /** File name of image at Commons. One meaning has one (or zero) image.
17 | */
18 | private String filename;
19 |
20 | /** Text of image caption. */
21 | private String caption;
22 |
23 | /** Number of meaning could be presented.
24 | * -1 by default
25 | */
26 | private int meaning_number;
27 |
28 | public Image(String filename, String caption) {
29 | // -1, that is meaning number is absent
30 | this(filename, caption, -1);
31 | }
32 |
33 | public Image(String filename, String caption, int meaning_number) {
34 |
35 | if(filename.length() == 0)
36 | System.out.println("Error in constructor Image::Image(): filename is empty!");
37 |
38 | this.filename = filename;
39 | this.caption = caption;
40 | this.meaning_number = meaning_number;
41 | }
42 |
43 | /** Gets name of file at Commons.
44 | */
45 | public String getFilename() {
46 | return filename;
47 | }
48 |
49 | /** Gets text caption of image.
50 | */
51 | public String getCaption() {
52 | return caption;
53 | }
54 |
55 | /** Gets number of meaning related to this image.
56 | */
57 | public int getMeaningNumber() {
58 | return meaning_number;
59 | }
60 |
61 | // if(null == params || params.length == 0)
62 | //return NULL_STRING_ARRAY;
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/android/common_wiki_android/tests/src/wikokit/base/wikt/sql/quote/test/TQuotSourceTest.java:
--------------------------------------------------------------------------------
1 | package wikokit.base.wikt.sql.quote.test;
2 |
3 | import wikokit.base.wikipedia.language.LanguageType;
4 | import wikokit.base.wikipedia.sql.Connect;
5 | import wikokit.base.wikt.sql.TLang;
6 | import wikokit.base.wikt.sql.TPOS;
7 | import wikokit.base.wikt.sql.quote.TQuotSource;
8 | import android.content.Context;
9 | import android.database.sqlite.SQLiteDatabase;
10 | import junit.framework.TestCase;
11 |
12 | public class TQuotSourceTest extends TestCase {
13 |
14 | public Context context = null;
15 | Connect ruwikt_conn;
16 | SQLiteDatabase db;
17 |
18 | protected void setUp() throws Exception {
19 | super.setUp();
20 | ruwikt_conn = new Connect(context, LanguageType.ru);
21 | ruwikt_conn.openDatabase();
22 | db = ruwikt_conn.getDB();
23 | TLang.createFastMaps(db);
24 | TPOS.createFastMaps (db);
25 | }
26 |
27 | protected void tearDown() throws Exception {
28 | super.tearDown();
29 | ruwikt_conn.close();
30 | }
31 |
32 | public void testGet() {
33 | // zero sources
34 | String _name = "bla-bla-bla";
35 | TQuotSource s = TQuotSource.get (db, _name);
36 | assertNull(s);
37 |
38 | // there is quotation for this publisher
39 | _name = "Lib";
40 | s = TQuotSource.get(db, _name);
41 | assertNotNull(s);
42 | assertEquals(_name, s.getText());
43 | }
44 |
45 | public void testGetByID() {
46 | // zero
47 | int id = -1;
48 | TQuotSource s = TQuotSource.getByID(db, id);
49 | assertNull(s);
50 |
51 | // there is a publisher
52 | String _name = "Lib";
53 | s = TQuotSource.get(db, _name);
54 | assertNotNull(s);
55 |
56 | TQuotSource result_by_id = TQuotSource.getByID(db, s.getID());
57 | assertNotNull(result_by_id);
58 | assertEquals(_name, result_by_id.getText());
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/android/common_wiki_android/tests/src/wikokit/base/wikt/sql/test/TInflectionTest.java:
--------------------------------------------------------------------------------
1 | package wikokit.base.wikt.sql.test;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import wikokit.base.wikipedia.language.LanguageType;
6 | import wikokit.base.wikipedia.sql.Connect;
7 | import wikokit.base.wikt.sql.TInflection;
8 |
9 | import junit.framework.TestCase;
10 |
11 | public class TInflectionTest extends TestCase {
12 |
13 | public Context context = null;
14 | Connect ruwikt_conn;
15 |
16 | protected void setUp() throws Exception {
17 | super.setUp();
18 | ruwikt_conn = new Connect(context, LanguageType.ru);
19 | ruwikt_conn.openDatabase();
20 | }
21 |
22 | protected void tearDown() throws Exception {
23 | super.tearDown();
24 | ruwikt_conn.close();
25 | }
26 |
27 | public void testGet() {
28 | System.out.println("get_ru");
29 | SQLiteDatabase db = ruwikt_conn.getDB();
30 |
31 | String inflected_form = "test_TInflection_insert_ru";
32 |
33 | // let's not find unknown inflection
34 | TInflection p = TInflection.get(db, inflected_form);
35 | assertNull(p);
36 |
37 | // let's find existing inflection
38 | inflected_form = "bonvolu"; // in Russian Wiktionary
39 | TInflection p2 = TInflection.get(db, inflected_form);
40 | assertNotNull(p2);
41 |
42 | int freq = p2.getFreq();
43 | assertTrue(freq > 0);
44 | }
45 |
46 | public void testGetByID() {
47 | SQLiteDatabase db = ruwikt_conn.getDB();
48 |
49 | // let's find existing inflection
50 | String inflected_form = "bonvolu"; // in Russian Wiktionary
51 | TInflection p = TInflection.get(db, inflected_form);
52 | assertNotNull(p);
53 |
54 | TInflection p2 = TInflection.getByID(db, p.getID());
55 | assertNotNull(p2);
56 | assertEquals(p.getID(), p2.getID());
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/wiwordik/src/wiwordik/WConstants.java:
--------------------------------------------------------------------------------
1 | /* WConstants.fx - Constants and global variables used in Wiwordik.
2 | *
3 | * Copyright (c) 2011 Andrew Krizhanovsky
4 | * Distributed under EPL/LGPL/GPL/AL/BSD multi-license.
5 | */
6 |
7 | package wiwordik;
8 |
9 | import wikokit.base.wikipedia.language.LanguageType;
10 |
11 |
12 | public class WConstants {
13 |
14 | // GUI
15 |
16 | /** Width of word card. */
17 | public static int wordcard_width = 380; // old: wrapping_width
18 | public static int wordcard_min_width = 220;
19 |
20 | /** Width of word card. */
21 | public static int wordcard_height = 600;
22 | public static int wordcard_min_height = 120;
23 |
24 | public static Boolean DEBUGUI = false;
25 |
26 | /** Number of words visible in the list */
27 | public static int n_words_list = 31;
28 |
29 | /** Number of languages sorted by size (in dropdown list) */
30 | // public static int n_language_list_by_size = 200; // 100;
31 | // see LangChoice.fillChoiceBoxByLanguages
32 |
33 | // ===========
34 | // Wiktionary parsed database
35 | // ===========
36 |
37 | public static String wiwordik_version = "0.10";
38 |
39 | /** Skips #REDIRECT words if true. */
40 | public static boolean b_skip_redirects = false;
41 |
42 | //////////////////////////////
43 | // Release / publish parameters
44 |
45 | //var native_lang : LanguageType;
46 | public static LanguageType native_lang = LanguageType.ru;
47 | //public static LanguageType native_lang = LanguageType.en;
48 |
49 | /** If true, then SQLite database extracted from the .jar and stored
50 | * to the directory user.dir (Add .jar with SQLite database to the project).
51 | * If false, then SQLite database from the project local folder ./sqlite/
52 | */
53 | public static Boolean IS_RELEASE = false;
54 |
55 | /** true (SQLite), false (MySQL) */
56 | public static Boolean IS_SQLITE = false;
57 |
58 | // eo Parameters //
59 | //////////////////////////////
60 | }
61 |
--------------------------------------------------------------------------------
/hits_wiki/src/rfc2229/MobyParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MobyParser.java
3 | *
4 | * Copyright (c) 2005 Andrew Krizhanovsky /aka at mail.iias.spb.su/
5 | * Distributed under GNU Public License.
6 | */
7 |
8 | package rfc2229;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import wikipedia.util.StringUtil;
13 |
14 | import java.util.regex.Pattern;
15 | import java.util.regex.Matcher;
16 | //import java.util.regex.PatternSyntaxException;
17 | import wikipedia.util.StringUtilRegular;
18 |
19 | /** Parses text of Moby's word list */
20 | public class MobyParser {
21 |
22 | public MobyParser() {
23 | }
24 |
25 | /** Extracts words from the Moby's text.
26 | * Implementations:
27 | * 1. Takes substring from ":" till "."
28 | * 2. Split by comma ","
29 | * 3. Strip non-words letters, e.g. "\r\n backset " -> "backset"
30 | *
31 | * Example of source string:
32 | * 24 (3 in test) Moby Thesaurus words for "mulch":" \
33 | * \r\n backset, fallow,\r\n fertilize, culture,\r\n thin, work\r\n\r\n\r\n\r\n.\r\n
34 | */
35 | public static String[] getWords(String text) {
36 |
37 | Pattern p;
38 | Matcher m;
39 |
40 | // remove text from start till the first colon inclusively
41 | p = Pattern.compile("(?s)\\A[^\\:]*:");
42 | m = p.matcher(text);
43 | text = m.replaceFirst("");
44 |
45 | // remove text from last dot till the end inclusively
46 | p = Pattern.compile("(?s)\\..*?\\Z");
47 | m = p.matcher(text);
48 | text = m.replaceFirst("");
49 |
50 |
51 | String[] words = StringUtil.split(",", text);
52 | StringUtilRegular.stripNonWordLetters(words);
53 |
54 | // add unique words /replace by StringUtil.addOR/
55 | List result = new ArrayList();
56 | for(String w: words) {
57 | if(!result.contains(w)) {
58 | result.add(w);
59 | }
60 | }
61 | return (String[])result.toArray(new String[0]);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------