Compiler API for Python#
- class eot.wowool.native.core.compiler.Compiler#
A Compiler object can be used to compile rules or lexicons to an existing domain object.
from eot.wowool.native.core import Compiler, Domain from eot.wowool.native.core import Language from eot.wowool.document import Document # Build your domain Compiler.compile(source="""rule:{ 'car'} = Vehicle; """, output_file="car.dom") domain = Domain("car.dom") # Use your domain analyzer = Language("english") document = domain(analyzer(Document("nice car")))
A domain object can also be used to build a .dom file from either source files or input data.
1from eot.wowool.native.core import Compiler 2 3 d = Compiler( ) 4 d.add_source( r""" rule:{ Person .. <'work'> .. Company }= PersonWorkCompany;""" ) 5 d.add_source( r""" rule:{ Person .. Company }= PersonCompany;""" ) 6 results = d.save('profile.dom') 7 if not results.status: 8 print(results)
- static compile(output_file: Union[str, pathlib.Path], input_files: Optional[Union[List[str], List[pathlib.Path]]] = None, source: Optional[str] = None, language: Optional[str] = None, force: bool = False, unit_test: bool = False, strict: bool = False, threads: int = 4, verbose: str = 'fatal', parse_only: bool = False, ignore_codes: int = 0, disable_plugin_calls: bool = False, lxware: Optional[str] = None, logger_function: Callable[[int, str], None] = None) eot.wowool.native.core.compiler.Results #
Compile a given domain file.
- Parameters
output_file ([str,Path]) – Output file name of the domain ex: ‘drinks.dom’
input_files (list[str, Path]) – List of wow file to compile, ex: [ “beers.wow” , “wine.dom” ]
source (str) – Wowoolian source code.
language (str) – The language to use for the unit-tests
force (boolean) – Force a full build
unit_test (boolean) – Perform unit-test on the source file that contains @test arguments
verbose (str) –
strict (boolean) – Perform strict parsing of the wowool language.
from eot.wowool.native.core import Compiler # Build your domain. Compiler.compile( input_files=['test.wow'] , output_file='car.dom' )
- __init__()#
Instantiate a Compiler object
- add_source(source: str)#
Add wow source code to the domain object.
- Parameters
source (str) – wowool source code.
- add_file(wow_file: str)#
Add a wow file. A domain object is used to build a .dom file from either source files or input data.
- save(output_filename, parse_only=False, disable_plugin_calls=False, logger_function: Callable[[int, str], None] = None)#
Save the files or sources that have been added to the domain.
- Parameters
output_filename ([str,Path]) – The domain (.dom) filename.
parse_only (boolean) – Will not generate a dom file, but will only perform syntax checking.
from eot.wowool.native.core import Compiler, Domain from eot.wowool.native.core import Language from eot.wowool.annotation import Concept from eot.wowool.document import Document # Compile and save your domain compiler = Compiler() compiler.add_file("test.wow") results = compiler.save("beers.dom") if not results.status: print(results) exit(1) # Use you domain analyzer = Language("english") beers = Domain("beers.dom") document = beers(analyzer(Document("I like Rochefort And Duvel"))) for concept in Concept.iter(document): print(f"{concept.uri}: {concept.literal}")
Sentence: I like Rochefort And Duvel Beer: Rochefort Beer: Duvel
- class eot.wowool.native.core.compiler.Results#
Results object representing the compilation output.
from eot.wowool.native.core import Compiler import os # Make a temp rule file with open("test.wow", "w") as fd: fd.write("""lexicon{ Duvel, Rochefort }= Beer;""") # Compile and save your domain compiler = Compiler() compiler.add_file("test.wow") results = compiler.save("beers.dom") if not results.status: print(results) # Cleanup os.remove("test.wow")
test.wow:1:8: error Missing ':' after keyword ... lexicon{ Duvel, ... -----------^
- __init__(json_data)#
- property status#
Return whether the domain was successfully compiled
- property sink#
Return an error sink. Format of the sink is:
{ "test.wow" : [ { "type": "error", "line": 1, "column":8, "msg": "Missing ':' after keyword" } ] }