-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
from pyrdfrules.common.rule.resultrule import ResultRule | ||
from pyrdfrules.common.rule.rule.body import RuleBody | ||
from pyrdfrules.common.rule.rule.head import RuleHead | ||
from pyrdfrules.common.rule.ruleset import Ruleset | ||
|
||
|
||
class Result(): | ||
|
||
ruleset: Ruleset = None | ||
"""Ruleset generated by RDFRules. | ||
""" | ||
|
||
def __init__(self, data: dict) -> None: | ||
self.id = id | ||
self.data = data | ||
|
||
self._parse_data() | ||
|
||
pass | ||
|
||
def _parse_data(self): | ||
|
||
rules = [] | ||
|
||
for item in self.data: | ||
match item: | ||
case {'body': _, 'head': __, 'measures': ___}: | ||
# Item is a rule | ||
|
||
rule = ResultRule.model_construct(item) | ||
|
||
print(rule) | ||
|
||
pass | ||
case _: | ||
pass | ||
|
||
def get_ruleset(self) -> Ruleset: | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
from typing import List | ||
from pydantic import BaseModel | ||
|
||
from pyrdfrules.common.rule.rule.object import Object | ||
from pyrdfrules.common.rule.rule.predicate import Predicate | ||
from pyrdfrules.common.rule.rule.subject import Subject | ||
|
||
class RuleHead(BaseModel): | ||
|
||
item: any | ||
graphs: List[str] | ||
|
||
object: Object | ||
|
||
predicate: Predicate | ||
|
||
subject: Subject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class Object(BaseModel): | ||
|
||
type: str | ||
|
||
value: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
|
||
|
||
class Predicate(BaseModel): | ||
|
||
localName: str | ||
|
||
nameSpace: str | ||
|
||
prefix: Optional[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class Subject(BaseModel): | ||
|
||
type: str | ||
|
||
value: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
import logging | ||
import unittest | ||
|
||
from pyrdfrules.common.result.result import Result | ||
|
||
|
||
|
||
class TestRuleParsing(unittest.TestCase): | ||
|
||
def test_rule_parsing(self): | ||
""" | ||
Tests parsing of a rule. | ||
""" | ||
|
||
data = '[{"body": [{"graphs": ["<dbpedia>"], "object": {"type": "variable", "value": "?b"}, "predicate": {"localName": "subsequentWork", "nameSpace": "http://dbpedia.org/ontology/", "prefix": "dbo"}, "subject": {"type": "variable", "value": "?c"}}, {"graphs": ["<dbpedia>"], "object": {"type": "variable", "value": "?a"}, "predicate": {"localName": "artist", "nameSpace": "http://dbpedia.org/ontology/", "prefix": "dbo"}, "subject": {"type": "variable", "value": "?c"}}], "head": {"graphs": ["<yago>"], "object": {"type": "variable", "value": "?b"}, "predicate": "<created>", "subject": {"type": "variable", "value": "?a"}}, "measures": [{"name": "Support", "value": 845}, {"name": "HeadSupport", "value": 5803}, {"name": "PcaBodySize", "value": 871}, {"name": "PcaConfidence", "value": 0.9701492537313433}, {"name": "HeadSize", "value": 5803}, {"name": "HeadCoverage", "value": 0.14561433741168361}]}]' | ||
|
||
rules = json.loads(data) | ||
|
||
print(rules) | ||
|
||
result = Result(rules) | ||
|
||
print(rules) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters