'How can rdflib parse an arithmetic expression in RDF

To say an arithmetic expression like x=m/n^2, I express it in RDF as follows:

@prefix : <http://ex.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix math: <http://math.org/> .

:m a math:Constant;
        rdf:value 18.
:n a math:Constant;
        rdf:value 3.
:x  a math:Varible;
    math:equalTo [
      a math:devide; 
      math:_1st :m ;
      math:_2nd [
             a math:Power ;
             math:_1st :n ;
             math:_2nd 2 ]
 ].

It is visualized as shown below

Assume that python programs only know the meaning of operators defined in Math in advance, but not the variables and formulas in RDF files , Now how do I read this RDF file and restore this expression in Python?

I tried using RDflib's graph.triples(), graph.subject(), or graph.value(), but couldn't get the right results, I think the main problem is that I can't read everything in BNode correctly, anyone who can show me the right way to do it, thanks a lot!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source