The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
greeklexattribs.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * greeklexattribs.cpp - SWFilter descendant to set entry attributes
4  * for greek lexicons
5  *
6  * $Id: greeklexattribs.cpp 3511 2017-11-01 11:18:50Z scribe $
7  *
8  * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <string>
28 #include <greeklexattribs.h>
29 #include <swmodule.h>
30 
31 using std::string;
32 
34 
36 }
37 
38 
39 char GreekLexAttribs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
40 
41  if (module->isProcessEntryAttributes()) {
42  const char *from;
43  bool inAV = false;
44  string phrase;
45  string freq;
46  char val[128], *valto;
47  char wordstr[11];
48  const char *currentPhrase = 0;
49  const char *currentPhraseEnd = 0;
50  int number = 0;
51 
52 
53  for (from = text.c_str(); *from; from++) {
54  if (inAV) {
55  if (currentPhrase == 0) {
56  if (isalpha(*from))
57  currentPhrase = from;
58  }
59  else {
60  if ((!isalpha(*from)) && (*from != ' ') && (*from != '+') && (*from !='(') && (*from != ')') && (*from != '\'')) {
61  if (*from == '<') {
62  if (!currentPhraseEnd)
63  currentPhraseEnd = from - 1;
64  for (; *from && *from != '>'; from++) {
65  if (!strncmp(from, "value=\"", 7)) {
66  valto = val;
67  from += 7;
68  for (unsigned int i = 0; from[i] != '\"' && i < 127; i++)
69  *valto++ = from[i];
70  *valto = 0;
71  sprintf(wordstr, "%03d", number+1);
72  module->getEntryAttributes()["AVPhrase"][wordstr]["CompoundedWith"] = val;
73  from += strlen(val);
74  }
75  }
76  continue;
77  }
78 
79  phrase = "";
80  phrase.append(currentPhrase, (int)(((currentPhraseEnd>currentPhrase)?currentPhraseEnd:from) - currentPhrase)-1);
81  currentPhrase = from;
82  while (*from && isdigit(*from)) from++;
83  freq = "";
84  freq.append(currentPhrase, (int)(from - currentPhrase));
85  if ((freq.length() > 0) && (phrase.length() > 0)) {
86  sprintf(wordstr, "%03d", ++number);
87  if ((strchr(phrase.c_str(), '(') > phrase.c_str()) && (strchr(phrase.c_str(), ')') > phrase.c_str() + 1)) {
88  string tmp = phrase.substr(0, phrase.find_first_of("("));
89  phrase.erase(phrase.find_first_of("("), 1);
90  phrase.erase(phrase.find_first_of(")"), 1);
91  phrase.erase(0,phrase.find_first_not_of("\r\n\v\t ")); phrase.erase(phrase.find_last_not_of("\r\n\v\t ")+1);
92  module->getEntryAttributes()["AVPhrase"][wordstr]["Alt"] = phrase.c_str();
93  phrase = tmp;
94  }
95  phrase.erase(0,phrase.find_first_not_of("\r\n\v\t ")); phrase.erase(phrase.find_last_not_of("\r\n\v\t ")+1);
96  freq.erase(0,freq.find_first_not_of("\r\n\v\t ")); freq.erase(freq.find_last_not_of("\r\n\v\t ")+1);
97  module->getEntryAttributes()["AVPhrase"][wordstr]["Phrase"] = phrase.c_str();
98  module->getEntryAttributes()["AVPhrase"][wordstr]["Frequency"] = freq.c_str();
99  currentPhrase = 0;
100  currentPhraseEnd = 0;
101  }
102  }
103  }
104  if (*from == ';') inAV = false;
105 
106  }
107  else if (!strncmp(from, "AV-", 3)) {
108  inAV = true;
109  from+=2;
110  }
111  }
112  }
113  return 0;
114 }
115 
116 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
const char * c_str() const
Definition: swbuf.h:158
virtual bool isProcessEntryAttributes() const
Definition: swmodule.h:832
virtual AttributeTypeList & getEntryAttributes() const
Definition: swmodule.h:817
#define SWORD_NAMESPACE_END
Definition: defs.h:40
const char * string
Definition: regex.c:5014
Definition: swkey.h:77