OK, so Wikidata does not have a field for the formal charge...
bind(
if(substr(?inchikey,27) = "N", "0"^^xsd:integer,
if(substr(?inchikey,27) = "M", "-1"^^xsd:integer,
if(substr(?inchikey,27) = "O", "+1"^^xsd:integer,
if(substr(?inchikey,27) = "L", "-2"^^xsd:integer,
if(substr(?inchikey,27) = "P", "+2"^^xsd:integer,
if(substr(?inchikey,27) = "K", "-3"^^xsd:integer,
if(substr(?inchikey,27) = "J", "-4"^^xsd:integer,
if(substr(?inchikey,27) = "I", "-5"^^xsd:integer,
if(substr(?inchikey,27) = "F", "-8"^^xsd:integer,
"999"^^xsd:integer # ERROR
)
)
)
)
)
)
)
)
)
as ?charge
)
It probably goes well for most things, and eager to learn about exceptions...