Skip to content

Commit

Permalink
Updated output format for drepr extension from String to OutputFormat…
Browse files Browse the repository at this point in the history
… Enum
  • Loading branch information
punith300i committed Jun 2, 2023
1 parent 164e27a commit 712e201
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sand/controllers/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sm.outputs.semantic_model as O
from flask import jsonify, request, make_response
from peewee import DoesNotExist, fn

from drepr.engine import OutputFormat
from werkzeug.exceptions import BadRequest, NotFound


Expand Down Expand Up @@ -121,7 +121,7 @@ def export_table_data(id: int):
rows: List[TableRow] = list(TableRow.select().where(TableRow.table == table))

# export the data using drepr library
content = DreprExport().export_data(table, rows, sm.data, 'TTL')
content = DreprExport().export_data(table, rows, sm.data, OutputFormat.TTL)
resp = make_response(content)
resp.headers["Content-Type"] = "text/ttl; charset=utf-8"
if request.args.get("attachment", "false") == "true":
Expand Down
6 changes: 3 additions & 3 deletions sand/extension_interface/export.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABC, abstractmethod
from typing import List, AnyStr
from typing import List

import sm.outputs.semantic_model as O
from sand.models.table import Table, TableRow
from sand.models.table import Table, TableRow
from drepr.models import DRepr
from drepr.engine import OutputFormat


class IExport(ABC):
Expand All @@ -20,6 +20,6 @@ def export_data_model(self, table: Table, sm: O.SemanticModel) -> DRepr:

@abstractmethod
def export_data(self, table: Table, rows: List[TableRow], sm: O.SemanticModel,
output_format: AnyStr):
output_format: OutputFormat):
"""Search Class using name"""
pass
7 changes: 4 additions & 3 deletions sand/extensions/export/drepr/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Set, AnyStr
from typing import List, Set
from enum import Enum
from sand.config import SETTINGS
from sand.models.ontology import OntProperty, OntPropertyAR, OntPropertyDataType
from sand.models.table import Table, TableRow
Expand Down Expand Up @@ -127,7 +128,7 @@ def export_data_model(self, table: Table, sm: O.SemanticModel) -> DRepr:
)

def export_data(self, table: Table, rows: List[TableRow], sm: O.SemanticModel,
output_format: AnyStr):
output_format: OutputFormat):
"""Convert a relational table into RDF format"""
if len(table.columns) == 0:
# no column, no data
Expand All @@ -142,7 +143,7 @@ def export_data(self, table: Table, rows: List[TableRow], sm: O.SemanticModel,
content = execute(
ds_model=self.export_data_model(table, sm),
resources=resources,
output=MemoryOutput(OutputFormat.__getitem__(output_format)),
output=MemoryOutput(output_format),
debug=False,
)
return content

0 comments on commit 712e201

Please sign in to comment.