Assignment 3 (GLF Intro)

Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.

Assignment 3 (GLF Intro)
Dear all,

I’ve created the third homework assignment. You can find it at https://kwarc.info/teaching/LBS/assignment.pdf.
This requires that you set up GLF in some form. I’ll try to provide all the instructions you need in this post.
As always: If you have any technical difficulties, feel free to ask here. We can also try to resolve problems on Wednesday.

Prerequisites

  • You need to have the Grammatical Framework (GF) installed. Instructions are here: https://www.grammaticalframework.org/download/index.html
  • I assume you have a recent version of Python installed (I think version 3.6 or newer should work)
  • It would be good if you have git installed (that is essentially a requirement for MMT anyway)

You need to have MMT installed. Instructions are here: https://uniformal.github.io//doc/setup/
However, we need some feature that have not been released yet. So instead, you should try to use the following file: https://kwarc.info/teaching/LBS/resources/mmt.jar
If you have installed MMT already, it should suffice to replace the file at [m]MMT/deploy[/m] and run [m]java -jar mmt.jar :setup[/m].

You need to clone the LBS repository into the right place.
The easy way: run [m]java -jar mmt.jar lmh install Teaching/lbs1920[/m]

If that doesn’t work: Follow the instructions in footnote 1.

Option 1: Use Jupyter Notebooks
You need to install the GLF Jupyter kernel for this. Since it still under development, you can’t just install it from [m]pip[/m].

Step 1:
Clone the GLF Kernel repository and pick the right branch:

git clone https://github.com/kaiamann/glf_kernel
git checkout -b lbs

Step 2:
In the file [m]glf_kernel/MMTInterface.py[/m] change the value of [m]MMT_LOCATION[/m] to point to the MMT folder that was created during the installation.
That folder should contain among other things a [m]deploy[/m] folder.

Step 3:
Install the kernel (which should also install Jupyter). Run the following commands from the cloned repository:

sudo python3 -m pip install .
python3 -m glf_kernel.install

Now you should be able to start the notebooks with [m]jupyter notebook[/m].

Option 2: Don’t use Jupyter
In this case you can edit the GF files in any editor you want (but keep them in the place they are!) and test them with the normal GF command line.
Similarly, you can edit the [m]assignment3.mmt[/m] file with jedit/IntelliJ.

In order to connect the two, you can use the attached Python script.
Before running the script, you will have to adjust the values of [m]LOCATION_MMT_JAR[/m], [m]GF_BIN[/m] and [m]GF_CONCRETE_FILE[/m].
The remaining variables should already be set to the right values.

Running the script will import the GF grammars into MMT. So when you are done with the GF part, you should run it once so that MMT can properly typecheck your semantics construction view.
When you are done with everything, you can run the script to enter sentence and check the result.

Good luck and see you on Wednesday, :slight_smile:
Frederik


Footnote 1: Cloning the LBS repository manually

When you installed MMT, a folder called “MMT-Content” or maybe “MathHub” or maybe something else was created. It should contain a folder “MMT” with subfolders like “examples” or “urtheories”.
In this “MMT-Content” folder you should create a new folder called “Teaching”.
And into this “teaching” folder you should clone the repository https://gl.mathhub.info/Teaching/lbs1920.
Afterwards you should have a folder “MMT-Content/Teaching/lbs1920”. The exact spelling of “Teaching/lbs1920” is important!

Attachment:
SimpleGlf.py: https://fsi.cs.fau.de/unb-attachments/post_162232/SimpleGlf.py


One more comment for Windows users (from Max):
For using Jupyter on Windows, apparently this issue is relevant: https://stackoverflow.com/questions/58422817/jupyter-notebook-with-python-3-8-notimplementederror

And one more think (especially when using the Linux subsystem):
The GLF kernel requires at least Python version 3.6, otherwise you will get errors when running [m]python3 -m glf_kernel.install[/m]
Today we had issues, because the Ubuntu subsystem apparently had nothing newer than 3.5.

Best,
Frederik


Hi,

Just want to add: For those using Jupyter Notebook to do the assignment (probably in the future semesters), you might also need to set the variable self.archive

i set mine to self.archive = ‘MMT/urtheories/’ before it worked.

Cheers.

I get this error on my terminal when running the Assignment 3 notebook. But it seems to be unrelated to the problem I had.
hello,

generally when running Jupyter Notebooks, the [] on the left of the cell indicates that the operation is still running.
But sometimes, for GF, the [
] can be shown even when the cell is completely executed. And so, the error below was shown when the cell was executed and I thought it was related to the never ending [*]. But I just realized that the cell was done executing anyway.

Bottom line is (FYI) if there is a cell for GF showing the [*] on the left, maybe and just maybe the cell is already done running.
Don’t wait like I did for it to “terminate” because it probably already has.

Cheers.


[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/ipykernel/kernelbase.py”, line 268, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File “/usr/local/lib/python3.7/site-packages/tornado/gen.py”, line 735, in run
value = future.result()
File “/usr/local/lib/python3.7/site-packages/tornado/gen.py”, line 209, in wrapper
yielded = next(result)
File “/usr/local/lib/python3.7/site-packages/ipykernel/kernelbase.py”, line 541, in execute_request
user_expressions, allow_stdin,
File “/Users/zzpp/PycharmProjects/glf_kernel/glf_kernel/kernel.py”, line 112, in do_execute
messages = self.GFRepl.handle_input(code)
File “/Users/zzpp/PycharmProjects/glf_kernel/glf_kernel/GLFRepl.py”, line 103, in handle_input
message=self.handle_grammar(code, parse_dict[‘name’])))
File “/Users/zzpp/PycharmProjects/glf_kernel/glf_kernel/GLFRepl.py”, line 273, in handle_grammar
build_result = self.mmtInterface.build_file(file_name) # build the Grammar with the GlfBuild extension
File “/Users/zzpp/PycharmProjects/glf_kernel/glf_kernel/MMTInterface.py”, line 145, in build_file
return resp.json()
File “/usr/local/lib/python3.7/site-packages/requests/models.py”, line 897, in json
return complexjson.loads(self.text, **kwargs)
File “/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/init.py”, line 348, in loads
return _default_decoder.decode(s)
File “/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


Hey,

I just realized thaz I posted this question in the wrong thread initially.

The construct and show commands don’t seem to be working for me. I simply get a “command not found” error.
I installed via the official installation guide and am using GLF through jupyter notebooks. Any idea on throubleshooting?