<jupyter_start><jupyter_text>rdf_demoThis notebook demonstrates the rdf data generated by a HoboReader instance.  Create HoboReader instance and read in csv file<jupyter_code>from hoboreader import HoboReader
h=HoboReader('sample_hobo_data.csv')<jupyter_output><empty_output><jupyter_text>Create rdf data<jupyter_code>g=h.get_rdf(my_sensor_id=r'http://www.example.org/MyHobo',
            my_sensor_model='Hobo Pendant',
            my_sensor_manufacturer='Onset',
            my_feature_of_interest_id=r'http://www.example.org/MyLivingRoom')<jupyter_output><empty_output><jupyter_text>Query graph  Number of triples<jupyter_code>len(g)<jupyter_output><empty_output><jupyter_text>What predicates are used?<jupyter_code>qres = g.query(
"""
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

    SELECT ?p (COUNT(?p) AS ?count)
    WHERE 
    {
        ?s ?p ?o .
    }
    GROUP BY ?p
"""
)
[[str(x) for x in row] for row in qres]<jupyter_output><empty_output><jupyter_text>What classes are used?<jupyter_code>qres = g.query(
"""
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

    SELECT ?o (COUNT(?o) AS ?count)
    WHERE 
    {
        ?s a ?o .
    }
    GROUP BY ?o
"""
)
[[str(x) for x in row] for row in qres]<jupyter_output><empty_output><jupyter_text>Get sensor serial number<jupyter_code>q="""
SELECT ?result 
WHERE 
    { 
        ?sensor a sosa:Sensor . 
        ?property rdfs:label "Serial number" .
        ?observation sosa:hasFeatureOfInterest ?sensor ;
            sosa:observedProperty ?property ;
            sosa:hasSimpleResult ?result .
    }
"""
result=list(g.query(q))
sn=result[0][0]
sn<jupyter_output><empty_output><jupyter_text>Get sensor uri<jupyter_code>q="""
SELECT * 
WHERE 
    { 
        ?s a sosa:Sensor . 
        
    }
"""
sensor_uri=list(g.query(q))[0][0]
sensor_uri<jupyter_output><empty_output><jupyter_text>Get property labels<jupyter_code>q="""
SELECT ?label 
WHERE 
    { 
        ?property a ssn:Property . 
        ?property rdfs:label ?label
    }
"""
property_labels=list(g.query(q))
property_labels<jupyter_output><empty_output><jupyter_text>Get temperature data<jupyter_code>from datetime import datetime
q="""
SELECT ?datetime ?value ?unit 
WHERE
    {
        ?property rdfs:label 'Temp' . 
        ?observation sosa:observedProperty ?property ;
            sosa:hasResult ?result ;
            sosa:resultTime ?time .
        ?time time:inXSDDateTimeStamp ?datetime .
        ?result qudt:numericValue ?value ;
            qudt:unit ?unit .
    }
ORDER BY ?datetime
"""
result=g.query(q)
vars=[str(x) for x in result.vars]
temp_data=[(datetime.fromisoformat(str(x[0])),x[1].value,x[2]) for x in result]
temp_data[:2]
import pandas as pd
df=pd.DataFrame(columns=vars,data=temp_data)
df=df.set_index('datetime')
df.head()
%matplotlib inline
df['value'].plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13676371022342587, 'fraction_numerical': 0.012186865267433988, 'mean_word_length': 3.8363338788870704, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '279544', 'license': 'MIT', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1090, 'n_words': 194, 'path': 'demo/rdf_demo.ipynb', 'repo_name': 'building-energy/hoboreader', 'size': '2954'}