summaryrefslogtreecommitdiff
path: root/src/modules/filters/greeklexattribs.cpp
blob: 1c2533ded770335a5bc979ba9e33c8223810b947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/******************************************************************************
 *
 *  greeklexattribs.cpp -	SWFilter descendant to set entry attributes
 *				for greek lexicons
 *
 * $Id: greeklexattribs.cpp 2833 2013-06-29 06:40:28Z chrislit $
 *
 * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
 *	P. O. Box 2528
 *	Tempe, AZ  85280-2528
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <greeklexattribs.h>
#include <swmodule.h>

using std::string;

SWORD_NAMESPACE_START

GreekLexAttribs::GreekLexAttribs() {
}


char GreekLexAttribs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {

	if (module->isProcessEntryAttributes()) {
		const char *from;
		bool inAV = false;
		string phrase;
		string freq;
		char val[128], *valto;
		char wordstr[7];
		const char *currentPhrase = 0;
		const char *currentPhraseEnd = 0;
		int number = 0;


		for (from = text.c_str(); *from; from++) {
			if (inAV) {
				if (currentPhrase == 0) {
					if (isalpha(*from))
						currentPhrase = from;
				}
				else {
					if ((!isalpha(*from)) && (*from != ' ') && (*from != '+') && (*from !='(') && (*from != ')') && (*from != '\'')) {
						if (*from == '<') {
							if (!currentPhraseEnd)
								currentPhraseEnd = from - 1;
							for (; *from && *from != '>'; from++) {
								if (!strncmp(from, "value=\"", 7)) {
									valto = val;
									from += 7;
									for (unsigned int i = 0; from[i] != '\"' && i < 127; i++)
										*valto++ = from[i];
									*valto = 0;
									sprintf(wordstr, "%03d", number+1);
									module->getEntryAttributes()["AVPhrase"][wordstr]["CompoundedWith"] = val;
									from += strlen(val);
								}
							}
							continue;
						}

						phrase = "";
						phrase.append(currentPhrase, (int)(((currentPhraseEnd>currentPhrase)?currentPhraseEnd:from) - currentPhrase)-1);
						currentPhrase = from;
						while (*from && isdigit(*from)) from++;
						freq = "";
						freq.append(currentPhrase, (int)(from - currentPhrase));
						if ((freq.length() > 0) && (phrase.length() > 0)) {
							sprintf(wordstr, "%03d", ++number);
							if ((strchr(phrase.c_str(), '(') > phrase.c_str()) && (strchr(phrase.c_str(), ')') > phrase.c_str() + 1)) {
								string tmp = phrase.substr(0, phrase.find_first_of("("));
								phrase.erase(phrase.find_first_of("("), 1);
								phrase.erase(phrase.find_first_of(")"), 1);
								phrase.erase(0,phrase.find_first_not_of("\r\n\v\t ")); phrase.erase(phrase.find_last_not_of("\r\n\v\t ")+1);
								module->getEntryAttributes()["AVPhrase"][wordstr]["Alt"] = phrase.c_str();
								phrase = tmp;
							}
							phrase.erase(0,phrase.find_first_not_of("\r\n\v\t ")); phrase.erase(phrase.find_last_not_of("\r\n\v\t ")+1);
							freq.erase(0,freq.find_first_not_of("\r\n\v\t ")); freq.erase(freq.find_last_not_of("\r\n\v\t ")+1);
							module->getEntryAttributes()["AVPhrase"][wordstr]["Phrase"] = phrase.c_str();
							module->getEntryAttributes()["AVPhrase"][wordstr]["Frequency"] = freq.c_str();
							currentPhrase = 0;
							currentPhraseEnd = 0;
						}
					}
				}
				if (*from == ';') inAV = false;

			}
			else if (!strncmp(from, "AV-", 3)) {
				inAV = true;
				from+=2;
			}
		}
	}
	return 0;
}


SWORD_NAMESPACE_END