Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Exception not raised while using python library #141

@NicoRobertIn

Description

@NicoRobertIn

Issue Description:

While using python library and loading a turtle file with an undefined prefix Corese outputs an error in the console but does not raise an exception on python library side... Is this normal?

In a python script

Steps to Reproduce:

from queue import Queue, Empty
from sys import builtin_module_names
from subprocess import Popen, PIPE, DEVNULL
from threading  import Thread
from time import sleep
from atexit import register
from py4j.java_gateway import JavaGateway

def enqueue_output(out, queue):
    for line in iter(out.readline, b''):
        queue.put(line)
    out.close()

ON_POSIX = 'posix' in builtin_module_names
error_queue = Queue()

def get_error_line():
    try:
        return error_queue.get_nowait()
    except Empty:
        return ""


def get_error_output():
    total_output = []
    current_line = "a"

    while len(current_line) > 0:
        current_line = get_error_line()
        if isinstance(current_line, bytes):
            current_line = current_line.decode('utf-8')
        total_output.append(current_line)

    return "\n".join(total_output).strip()    

# Start java gateway
java_process = Popen(
    ['java', '-jar', '-Dfile.encoding=UTF-8', 'corese-library-python-4.4.1.jar'],
    stdout=PIPE,
    stderr=DEVNULL,
    close_fds=ON_POSIX
)
reader_thread = Thread(target=enqueue_output, args=(java_process.stdout, error_queue))
reader_thread.daemon = True # thread dies with the program
reader_thread.start()

# Waiting for the java server to start up
sleep(1)
gateway = JavaGateway()
register(gateway.shutdown)

# Import of class
Graph = gateway.jvm.fr.inria.corese.core.Graph
Load = gateway.jvm.fr.inria.corese.core.load.Load

def load(path):
    """Load a graph from a local file or a URL

    :param path: local path or a URL or a list of these
    :returns: the graph load
    """

    graph = Graph()

    ld = Load.create(graph)

    try:
        get_error_output()
        ld.parse(path)
        graph = Graph()
        ld = Load.create(graph)
        ld.parse(path)
        syntax_errors = get_error_output()
        print("syntax errors", syntax_errors)

        return graph

    except Exception as e:
        # syntax_errors = parse_syntax_errors()
        print("error", str(e).strip())

load("inconsistant.ttl")

In inconsistant.ttl

@prefix owl: <http://www.w3.org/2002/07/owl#> .

ex:A a oxl:Class .

Expected Behavior:

The print should be "error [Thread-1] ERROR fr.inria.corese.sparql.triple.parser.ASTQuery - Undefined prefix: oxl:Class"

Actual Behavior:

The print is "syntax errors [Thread-1] ERROR fr.inria.corese.sparql.triple.parser.ASTQuery - Undefined prefix: oxl:Class"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions