-
-
Notifications
You must be signed in to change notification settings - Fork 88
An API is available through the SymjaServer.java which implements a undertow server.
Make sure the Oracle Java 8 development kit (JDK8) is installed. At a terminal you can type java -version
to see if it is installed.
If not, head to the Oracle JDK8 download page and follow the installation instructions.
Download the latest Symja release from
Unzip the download in a separate folder and modify the jsonapi-server.bat
file to use your Java 8 installation path to run the Symja JSON API Server.
"%JAVA_HOME%\bin\java" -Dfile.encoding=UTF-8 -classpath "lib/*" org.matheclipse.api.SymjaServer
If you start this server
you can for example evaluate D(Sin(x),x)
with the URL
and get a response in JSON format.
{
"queryresult" : {
"success" : "true",
"error" : "false",
"numpods" : 3,
"version" : "0.1",
"pods" : [ {
"title" : "Input",
"scanner" : "Identity",
"error" : "false",
"numsubpods" : 1,
"subpods" : [ {
"plaintext" : "D(Sin(x),x)",
"sinput" : "D(Sin(x),x)",
"latex" : "\\frac{d}{{dx}}\\sin (x)"
} ]
}, {
"title" : "Derivative",
"scanner" : "Derivative",
"error" : "false",
"numsubpods" : 1,
"subpods" : [ {
"plaintext" : "Cos(x)",
"sinput" : "D(Sin(x),x)",
"latex" : "\\cos (x)"
} ]
}, {
"title" : "Alternate form",
"scanner" : "Simplification",
"error" : "false",
"numsubpods" : 1,
"subpods" : [ {
"plaintext" : "1/(2*E^(I*x))+E^(I*x)/2",
"sinput" : "TrigToExp(Cos(x))",
"latex" : "\\frac{1}{2\\,{e}^{i \\,x}}+\\frac{{e}^{i \\,x}}{2}"
} ]
} ]
}
}
Alternatively, if you're using the github developer repository you can run this Maven command inside a Gitpod ready-to-code console.
mvn -f pom.xml exec:java@api -pl matheclipse-api
The following request parameters are available. The input parameter i
must be available exactly once.
The format parameter f
can be set multiple times.
- i: the expression which should be evaluated in URL encoded form
- f:
plaintext
- returns the result inplaintext
ormarkdown
format - f:
latex
- returns the result inlatex
format - f:
mathml
- returns the result inmathml
format - s:
true
(any value) - strict Symja expression parsing, if omitted or not set a "fuzzy parser" was used to interpret the input expression
See the specification for symja.org
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class SymjaClientExample {
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
// JSON URL to Java object
try {
JsonNode node =
mapper.readTree(
new URL(
"http://localhost:8080/v1/api?i=D(Sin(x)%2Cx)&f=latex&f=plaintext&f=sinput&appid=DEMO"));
System.out.println(node.toPrettyString());
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}