Skip to content
Snippets Groups Projects
Unverified Commit 771c0799 authored by Tomáš Pecka's avatar Tomáš Pecka
Browse files

worker: output also latex representation if available

parent 5c757439
No related branches found
No related tags found
1 merge request!62Dev tp
...@@ -2,6 +2,7 @@ export interface StringNodeOutput { ...@@ -2,6 +2,7 @@ export interface StringNodeOutput {
plain?: string, plain?: string,
pretty?: string, pretty?: string,
dot?: string, dot?: string,
latex?: string,
} }
   
export interface NodeOutputs { export interface NodeOutputs {
......
...@@ -35,6 +35,10 @@ Json::Value replyOutputs(const AlgorithmGraph::EvaluatedGraph& eval) ...@@ -35,6 +35,10 @@ Json::Value replyOutputs(const AlgorithmGraph::EvaluatedGraph& eval)
outputsJson[nodeId]["result"]["dot"] = output; outputsJson[nodeId]["result"]["dot"] = output;
} }
   
for (const auto& [nodeId, output] : eval.latexOutputs) {
outputsJson[nodeId]["result"]["latex"] = output;
}
for (const auto& [nodeId, outputType] : eval.types) { for (const auto& [nodeId, outputType] : eval.types) {
outputsJson[nodeId]["type"] = outputType; outputsJson[nodeId]["type"] = outputType;
} }
......
...@@ -34,6 +34,7 @@ AlgorithmGraph::EvaluatedGraph AlgorithmGraph::evaluate() ...@@ -34,6 +34,7 @@ AlgorithmGraph::EvaluatedGraph AlgorithmGraph::evaluate()
std::map<std::string, std::string> outputs; std::map<std::string, std::string> outputs;
std::map<std::string, std::string> prettyOutputs; std::map<std::string, std::string> prettyOutputs;
std::map<std::string, std::string> dotOutputs; std::map<std::string, std::string> dotOutputs;
std::map<std::string, std::string> latexOutputs;
std::map<std::string, std::string> resultTypes; std::map<std::string, std::string> resultTypes;
cli::Environment environment; cli::Environment environment;
   
...@@ -61,10 +62,14 @@ AlgorithmGraph::EvaluatedGraph AlgorithmGraph::evaluate() ...@@ -61,10 +62,14 @@ AlgorithmGraph::EvaluatedGraph AlgorithmGraph::evaluate()
dotOutputs[node->getId()] = std::move(*nodeRes); dotOutputs[node->getId()] = std::move(*nodeRes);
} }
   
if (auto nodeRes = node->getResultLatex()) {
latexOutputs[node->getId()] = std::move(*nodeRes);
}
if (auto nodeType = node->getResultType()) { if (auto nodeType = node->getResultType()) {
resultTypes[node->getId()] = ext::to_string(nodeType); resultTypes[node->getId()] = ext::to_string(nodeType);
} }
} }
   
return {outputs, prettyOutputs, dotOutputs, resultTypes}; return {outputs, prettyOutputs, dotOutputs, latexOutputs, resultTypes};
} }
...@@ -14,6 +14,7 @@ public: ...@@ -14,6 +14,7 @@ public:
std::map<std::string, std::string> outputs; std::map<std::string, std::string> outputs;
std::map<std::string, std::string> prettyOutputs; std::map<std::string, std::string> prettyOutputs;
std::map<std::string, std::string> dotOutputs; std::map<std::string, std::string> dotOutputs;
std::map<std::string, std::string> latexOutputs;
std::map<std::string, std::string> types; std::map<std::string, std::string> types;
}; };
   
......
...@@ -82,6 +82,12 @@ public: ...@@ -82,6 +82,12 @@ public:
*/ */
virtual std::optional<std::string> getResultDot() { return std::nullopt; } virtual std::optional<std::string> getResultDot() { return std::nullopt; }
   
/**
* Returns the result of the node printed with convert::LatexConverter
* @return std::optional result of evaluation
*/
virtual std::optional<std::string> getResultLatex() { return std::nullopt; }
/** /**
* Returns the type of the result of the algorithm node or std::nullopt for other nodes. * Returns the type of the result of the algorithm node or std::nullopt for other nodes.
* @see core::type_details * @see core::type_details
......
...@@ -37,6 +37,11 @@ std::optional<std::string> OutputNode::getResultDot() ...@@ -37,6 +37,11 @@ std::optional<std::string> OutputNode::getResultDot()
return resultDot; return resultDot;
} }
   
std::optional<std::string> OutputNode::getResultLatex()
{
return resultLatex;
}
std::optional<core::type_details> OutputNode::getResultType() std::optional<core::type_details> OutputNode::getResultType()
{ {
return resultType; return resultType;
...@@ -58,4 +63,10 @@ void OutputNode::evaluate(abstraction::TemporariesHolder& environment) ...@@ -58,4 +63,10 @@ void OutputNode::evaluate(abstraction::TemporariesHolder& environment)
resultDot = utils::trim(abstractValueToString(composeValue)); resultDot = utils::trim(abstractValueToString(composeValue));
} catch (...) { } catch (...) {
} }
try {
auto composeValue = abstraction::EvalHelper::evalAlgorithm(environment, "convert::LatexConverter", {}, {params[0]}, abstraction::AlgorithmCategories::AlgorithmCategory::NONE);
resultLatex = utils::trim(abstractValueToString(composeValue));
} catch (...) {
}
} }
...@@ -25,6 +25,8 @@ public: ...@@ -25,6 +25,8 @@ public:
   
std::optional<std::string> getResultDot() override; std::optional<std::string> getResultDot() override;
   
std::optional<std::string> getResultLatex() override;
/** /**
* Returns result type of the input * Returns result type of the input
*/ */
...@@ -40,4 +42,5 @@ protected: ...@@ -40,4 +42,5 @@ protected:
std::optional<core::type_details> resultType; // FIXME: core::type_details doesn't have an 0-param constructor so it is uninitialized until the actual evaluation takes place std::optional<core::type_details> resultType; // FIXME: core::type_details doesn't have an 0-param constructor so it is uninitialized until the actual evaluation takes place
std::optional<std::string> resultCompose; std::optional<std::string> resultCompose;
std::optional<std::string> resultDot; std::optional<std::string> resultDot;
std::optional<std::string> resultLatex;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment