Debian Codegraph @

Source/Control/Interface/CommandLine/CSPARQLFileComandLinePreparationTranslator.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CSPARQLFileComandLinePreparationTranslator.h"
22
23
24 namespace Konclude {
25
26 namespace Control {
27
28 namespace Interface {
29
30 namespace CommandLine {
31
32 CSPARQLFileComandLinePreparationTranslator::CSPARQLFileComandLinePreparationTranslator(CLoaderFactory *loaderFactory) : CCommandLinePreparationTranslator(loaderFactory) {
33 mInterfaceTypeString = QString("CLI");
34 mMinNecessaryArguments = true;
35 mFirstArgumentTranslation = false;
36 mSPARQLQueryFileTranslated = false;
37 mReasonerConfList.append(QString("+=Konclude.Calculation.Querying.ComplexQueryingSupport=true"));
38 mReasonerConfList.append(QString("+=Konclude.Calculation.Optimization.RepresentativePropagation=false"));
39 mReasonerConfList.append(QString("+=Konclude.Calculation.Optimization.SignatureMirroringBlocking=false"));
40 }
41
42
43 CSPARQLFileComandLinePreparationTranslator::~CSPARQLFileComandLinePreparationTranslator() {
44 }
45
46 QStringList CSPARQLFileComandLinePreparationTranslator::combineTranslatedArguments() {
47 QStringList translatedArgList;
48
49 if (!mFirstArgumentTranslation) {
50 mMinNecessaryArguments = false;
51 }
52
53 if (!mMinNecessaryArguments) {
54 LOG(ERROR,getLogDomain(),logTr("Execution with inadequate command line arguments."),this);
55 mHelpRequested = true;
56 }
57
58 if (!mSPARQLQueryFileTranslated) {
59 LOG(ERROR, getLogDomain(), logTr("SPARQL query file not specified."), this);
60 mHelpRequested = true;
61 }
62
63 if (!mHelpRequested) {
64 if (mLogConfList.isEmpty()) {
65 mLogConfList.append(QString("-ConfigurableCoutLogObserverLoader -LoggerConfigurationLoader"));
66 }
67 translatedArgList += mLogConfList;
68 translatedArgList += mGeneralConfList;
69
70 translatedArgList += QString("-DefaultReasonerLoader ");
71 translatedArgList += mReasonerConfList;
72 translatedArgList += mGeneralConfList;
73
74 if (!mConfigConfList.isEmpty()) {
75 translatedArgList += QString("-OWLlinkBatchFileLoader +=Konclude.OWLlink.CloseAfterProcessedRequest=false +=Konclude.OWLlink.BlockUntilProcessedRequest=true");
76 translatedArgList += mConfigConfList;
77 }
78
79 if (mRequestFileTranslated) {
80 translatedArgList += QString("-CLILoadingBatchProcessingLoader +=Konclude.CLI.CloseAfterProcessedRequest=false +=Konclude.CLI.BlockUntilProcessedRequest=true");
81 translatedArgList += mRequestConfList;
82 }
83
84 if (mExtendendLogging) {
85 translatedArgList += QString("+=Konclude.SPARQL.LoggingExtendedProcessingTimes=true");
86 }
87
88
89 translatedArgList += QString("-SPARQLBatchFileLoader +=Konclude.SPARQL.CloseAfterProcessedRequest=true +=Konclude.SPARQL.BlockUntilProcessedRequest=true +=Konclude.SPARQL.RequestFile=%1 +=Konclude.SPARQL.ResponseFile=%2").arg(mSPARQLQueryFileName).arg(mSPARQLResponseFileName);
90
91
92 translatedArgList += mMiscellaneousList;
93 } else {
94 translatedArgList += QString("-ConfigurableCoutLogObserverLoader -CommandLineTranlatorHelpLoader");
95 }
96 return translatedArgList;
97 }
98
99 bool CSPARQLFileComandLinePreparationTranslator::translate(const QString& argumentText, QStringList& remainingArgList) {
100
101 bool argumentTranslated = false;
102
103
104 if (!mSkipTranslation) {
105
106 QString modArgText = argumentText.trimmed();
107 QString parmArgText;
108
109 if (modArgText.startsWith("-")) {
110 parmArgText = modArgText;
111 while (parmArgText.startsWith("-")) {
112 parmArgText.remove(0, 1);
113 parmArgText = parmArgText.trimmed();
114 }
115 }
116
117 if (parmArgText.size() == 1 && (parmArgText.indexOf("r") == 0 || parmArgText.indexOf("R") == 0 || parmArgText.indexOf("o") == 0 || parmArgText.indexOf("O") == 0)) {
118 // response/output file
119 argumentTranslated = true;
120 mSPARQLResponseFileName = "response.xml";
121 if (remainingArgList.count() > 0) {
122 mSPARQLResponseFileName = remainingArgList.takeFirst();
123 if (mSPARQLResponseFileName.trimmed().indexOf("-") == 0 || mSPARQLResponseFileName.trimmed().indexOf("+") == 0) {
124 mSPARQLResponseFileName = "response.xml";
125 }
126 }
127 if (!mGenerateAutoResponseFile) {
128 mRequestConfList.append(QString("+Konclude.SPARQL.ResponseFile=%1").arg(mSPARQLResponseFileName));
129 }
130 mResponseFileTranslated = true;
131
132
133 } else if (CCommandLinePreparationTranslator::translate(argumentText, remainingArgList)) {
134 argumentTranslated = true;
135
136 } else if (parmArgText.size() == 1 && (parmArgText.indexOf("s") == 0 || parmArgText.indexOf("S") == 0)) {
137 // sparql query/input file
138 QString configVal = "query.sparql";
139 if (remainingArgList.count() > 0) {
140 configVal = remainingArgList.takeFirst();
141 }
142 mSPARQLQueryFileName = configVal.trimmed();
143 argumentTranslated = true;
144 mSPARQLQueryFileTranslated = true;
145
146
147 } else if (modArgText == "sparqlfile" || modArgText == "sparql") {
148 argumentTranslated = true;
149 mFirstArgumentTranslation = true;
150 }
151 }
152 return argumentTranslated;
153 }
154
155
156
157 bool CSPARQLFileComandLinePreparationTranslator::canTranslate(const QString& string) {
158 if (QString::compare(string,"sparqlfile",Qt::CaseInsensitive) == 0 || QString::compare(string,"sparql",Qt::CaseInsensitive) == 0) {
159 return true;
160 }
161 return false;
162 }
163
164
165 }; // end namespace CommandLine
166
167 }; // end namespace Interface
168
169 }; // end namespace Control
170
171 }; // end namespace Konclude
172