Repository: RDFLib/rdflib

Issue:
Invalid serialization of xsd:decimal to scientific notation
I'm having an issue when doing a construct query using SPARQL is returning a rdflib graph with small numbers casted as a literal in scientific notation.
```
from SPARQLWrapper import SPARQLWrapper, RDFXML
from rdflib.term import URIRef, Literal
import sys

endpoint_url = "https://query.wikidata.org/sparql"
user_agent = "WDQS-example Python/%s.%s" % (sys.version_info[0], sys.version_info[1])
sparql = SPARQLWrapper(endpoint_url, agent=user_agent)
sparql.setReturnFormat(RDFXML)
query = """CONSTRUCT { ?s ?p ?o } WHERE { VALUES ?s { wd:Q184832 } ?s ?p ?o }"""
sparql.setQuery(query)
results = sparql.query().convert()

triples = set(results.triples((None, URIRef("http://www.wikidata.org/prop/direct/P2201"), None)))

for triple in triples:
    (s, p, o) = triple
    print("triple = %s", triple)
    print("str(o) = %s", str(o))
    print("o.value = %s/%s", type(o.value), o.value)
    print("o.n3() = %s", o.n3())

```
and it's output

```
triple = %s (rdflib.term.URIRef('http://www.wikidata.org/entity/Q184832'), rdflib.term.URIRef('http://www.wikidata.org/prop/direct/P2201'), rdflib.term.Literal('1E-31', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#decimal')))
str(o) = %s 1E-31
o.value = %s/%s <class 'decimal.Decimal'> 1E-31
o.n3() = %s "1E-31"^^<http://www.w3.org/2001/XMLSchema#decimal>
```
I believe o.value should be class 'float' 

If you serialize it this

```
results.serialize(destination="wikidump-000000001.ttl", format="turtle")

with open("wikidump-000000001.ttl","r") as fp:
    for line in fp:
        if "wdt:P2201" in line:
            print(line)
```

It outputs:

```
    wdt:P2201 1E-31.0 ;
```




Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/40288442/badge)](https://coveralls.io/builds/40288442)

Coverage decreased (-0.01%) to 75.694% when pulling **75eb4b48f926720eceedce527151ceb41f0cce91 on iafork:fix_decimal** into **06df8b6e3efc916144082360167fbf78a1bd398f on RDFLib:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/40288442/badge)](https://coveralls.io/builds/40288442)

Coverage decreased (-0.01%) to 75.694% when pulling **75eb4b48f926720eceedce527151ceb41f0cce91 on iafork:fix_decimal** into **06df8b6e3efc916144082360167fbf78a1bd398f on RDFLib:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/40288442/badge)](https://coveralls.io/builds/40288442)

Coverage decreased (-0.01%) to 75.694% when pulling **75eb4b48f926720eceedce527151ceb41f0cce91 on iafork:fix_decimal** into **06df8b6e3efc916144082360167fbf78a1bd398f on RDFLib:master**.


Patch:
diff --git a/rdflib/term.py b/rdflib/term.py
index d9e06d82..3fc4e968 100644
--- a/rdflib/term.py
+++ b/rdflib/term.py
@@ -1544,7 +1544,7 @@ _GenericPythonToXSDRules = [
     (bool, (lambda i: str(i).lower(), _XSD_BOOLEAN)),
     (int, (None, _XSD_INTEGER)),
     (long_type, (None, _XSD_INTEGER)),
-    (Decimal, (None, _XSD_DECIMAL)),
+    (Decimal, (lambda i: f"{i:f}", _XSD_DECIMAL)),
     (datetime, (lambda i: i.isoformat(), _XSD_DATETIME)),
     (date, (lambda i: i.isoformat(), _XSD_DATE)),
     (time, (lambda i: i.isoformat(), _XSD_TIME)),


Test patch:
diff --git a/test/test_literal.py b/test/test_literal.py
index 98cd18a8..a7de912b 100644
--- a/test/test_literal.py
+++ b/test/test_literal.py
@@ -1,3 +1,4 @@
+from decimal import Decimal
 import unittest
 import datetime
 
@@ -231,6 +232,9 @@ class TestXsdLiterals(unittest.TestCase):
             ("", XSD.hexBinary, bytes),
             ("UkRGTGli", XSD.base64Binary, bytes),
             ("", XSD.base64Binary, bytes),
+            ("0.0000000000000000000000000000001", XSD.decimal, Decimal),
+            ("0.1", XSD.decimal, Decimal),
+            ("1", XSD.integer, int),
         ]
         self.check_make_literals(inputs)
 
@@ -249,6 +253,7 @@ class TestXsdLiterals(unittest.TestCase):
             ("1921-05-01+00:00", XSD.date, datetime.date),
             ("1921-05-01+00:00", XSD.date, datetime.date),
             ("1921-05-01T00:00:00Z", XSD.dateTime, datetime.datetime),
+            ("1e-31", XSD.decimal, None),  # This is not a valid decimal value
         ]
         self.check_make_literals(inputs)