I created an ontology using protegee and now want to insert data using RDFLIB in python. Because I have to write the update sparql statements in string and my data comes in various types including, float64, integer, strings, and Datetime, I had to do some parsing and so not all are working. Below is a snippet of my code:
df=df.tail(2000)
for ind in df.index:
pData=df['Product'][ind]
lData=df['Lifecycle left in minutes'][ind]
XLPerc=df['Percent of Lifecycle left'][ind]
q = """
INSERT DATA
{
myontology:XP myontology:LifecycleData XL.
myontology:XP myontology:UseCycleData XU.
#myontology:XP myontology:LifecyclePer XLPerc.
myontology:XP myontology:Temperature XTemperature.
#myontology:XP myontology:LifecyclePer XLPerc
}
""".replace('XU', str(uData)).replace('XL', str(lData)).replace('XP', str(pData))
g.update(
q,
initNs={
"myontology":Namespace("https://js......../myontology.owl#")
}
)
So I am looping over my Dataframe (df) and inserting it into the ontology. Some are working and some are not working despite using the same method. I am getting ParseException error as follows:
ParseException: Expected end of text, found 'I' (at char 5), (line:2, col:5)
There is a long error code but this is the last line. I can provide more information if needed.
I do not know what the issue is, can somebody help me?
Thank you.
SN int64 Day object Temperature float64 Product object Start-time datetime64[ns] End-time datetime64[ns] Usecycle left int64 Manufacturing date datetime64[ns] Expiry Date datetime64[ns] Lifecycle left timedelta64[ns] Lifecycle in minutes float64 Lifecycle left in minutes float64 float64 Percent of Usecycle left float64 dtype: objectdf['Manufacturing date'].values[1], the result isnumpy.datetime64('2021-07-12T19:33:28.833921000'). But if I dodf['Manufacturing date'].values, I get a list ofdatetime64[ns]as'2021-06-28T11:22:45.004533000', '2021-05-28T11:22:45.004533000',myontology:XP myontology:LifecycleData 123 .worksmyontology:XP myontology:LifecycleData ABC .does not - strings or dates have to be put into quotes, and for dates for example you also have to append a datatype URI to the literal, e.g.myontology:XP ex:someDateProperty "2021-07-12T19:33:28.833921000"^^xsd:dateTime .