File: definition.cpp

package info (click to toggle)
bibledit-cloud 5.1.036-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 250,636 kB
  • sloc: xml: 915,934; ansic: 261,349; cpp: 92,628; javascript: 32,542; sh: 4,915; makefile: 586; php: 69
file content (139 lines) | stat: -rw-r--r-- 5,122 bytes parent folder | download | duplicates (2)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 Copyright (©) 2003-2025 Teus Benschop.
 
 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; either version 3 of the License, or
 (at your option) any later version.
 
 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.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#include <lexicon/definition.h>
#include <filter/roles.h>
#include <filter/string.h>
#include <filter/url.h>
#include <webserver/request.h>
#include <lexicon/logic.h>
#include <database/kjv.h>
#include <database/oshb.h>
#include <database/morphgnt.h>
#include <database/strong.h>


std::string lexicon_definition_url ()
{
  return "lexicon/definition";
}


bool lexicon_definition_acl (Webserver_Request& webserver_request)
{
  return roles::access_control (webserver_request, roles::consultant);
}


std::string lexicon_definition (Webserver_Request& webserver_request)
{
  // Retrieve the id: It may contain a Strong's number or a lemma.
  std::string id = webserver_request.query["id"];
  
  std::vector <std::string> renderings;
  
  if (!id.empty ()) {
    
    std::string letter = id.substr (0, 1);
    
    // ETCBC4 database.
    if (letter == HEBREW_ETCBC4_PREFIX) {
      renderings.push_back (lexicon_logic_render_etcbc4_morphology (id));
    }
    
    // King James Bible with Strong's numbers.
    else if (letter == KJV_LEXICON_PREFIX) {
      Database_Kjv database_kjv;
      std::string strong = database_kjv.strong (filter::strings::convert_to_int (id.substr (1)));
      std::string rendering = lexicon_logic_render_strongs_definition (strong);
      if (!rendering.empty ()) renderings.push_back (rendering);
      rendering = lexicon_logic_render_abbott_smiths_definition("", strong);
      if (!rendering.empty ()) renderings.push_back (rendering);
    }
    
    // Open Scriptures Hebrew with Strong's numbers and morphology.
    else if (letter == OSHB_PREFIX) {
      int rowid = filter::strings::convert_to_int (id.substr (1));
      Database_OsHb database_oshb;
      std::string morph = database_oshb.morph (rowid);
      renderings.push_back (lexicon_logic_hebrew_morphology_render (morph));
      std::string lemma = database_oshb.lemma (rowid);
      std::vector <std::string> strongs;
      std::vector <std::string> bdbs;
      lexicon_logic_convert_morphhb_parsing_to_strong (lemma, strongs, bdbs);
      for (size_t i = 0; i < strongs.size (); i++) {
        std::string rendering1 = lexicon_logic_render_strongs_definition (strongs[i]);
        if (!rendering1.empty ()) renderings.push_back (rendering1);
        std::stringstream rendering2;
        rendering2 << "<a href=" << std::quoted(BDB_PREFIX + bdbs[i]) << ">Brown Driver Briggs</a>";
        renderings.push_back (rendering2.str());
      }
    }
    
    // SBL Greek New Testament plus morphology.
    else if (letter == SBLGNT_PREFIX) {
      Database_MorphGnt database_morphgnt;
      Database_Strong database_strong;
      int rowid = filter::strings::convert_to_int (id.substr (1));
      // The part of speech.
      std::string pos = database_morphgnt.pos (rowid);
      std::string rendering = lexicon_logic_render_morphgnt_part_of_speech (pos);
      rendering.append (" ");
      // The parsing.
      std::string parsing = database_morphgnt.parsing (rowid);
      rendering.append (lexicon_logic_render_morphgnt_parsing_code (parsing));
      renderings.push_back (rendering);
      // The lemma.
      std::string lemma = database_morphgnt.lemma (rowid);
      std::vector <std::string> strongs = database_strong.strong (lemma);
      for (auto & lexicon_id : strongs) {
        rendering = lexicon_logic_render_strongs_definition (lexicon_id);
        if (!rendering.empty ()) renderings.push_back (rendering);
      }
      rendering = lexicon_logic_render_abbott_smiths_definition(lemma, "");
      if (!rendering.empty ()) renderings.push_back (rendering);
    }
    
    // Strong's Hebrew.
    else if (letter == "H") {
      std::string rendering = lexicon_logic_render_strongs_definition (id);
      if (!rendering.empty ()) renderings.push_back (rendering);
    }
    
    // Strong's Greek.
    else if (letter == "G") {
      std::string rendering = lexicon_logic_render_strongs_definition (id);
      if (!rendering.empty ()) renderings.push_back (rendering);
    }
    
    // Brown Driver Briggs lexicon.
    else if (letter == BDB_PREFIX) {
      std::string rendering = lexicon_logic_render_bdb_entry (id.substr (1));
      if (!rendering.empty ()) renderings.push_back (rendering);
    }
    
    // Unknown definition request.
    else {
      renderings.push_back (id);
    }
    
  }
  
  return filter::strings::implode (renderings, "<br>");
}