Skip to content

Commit

Permalink
Updated sastadev, clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
oktaal committed Mar 8, 2024
1 parent 8819941 commit f3c637d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
3 changes: 3 additions & 0 deletions mwe_query/canonicalform.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def mknewnode(stree: SynTree, mwetop: int, atts: List[str], annotations: List[in
newnode.attrib['maxnodecount'] = f'{len(stree)}'
return newnode


def expandnonheadwordnode(nonheadwordnode, phrasenodeproperties):
phraserel = gav(nonheadwordnode, 'rel')
newnonheadwordnode = copy.copy(nonheadwordnode)
Expand All @@ -402,6 +403,8 @@ def expandnonheadwordnode(nonheadwordnode, phrasenodeproperties):
phrasenode.attrib['rel'] = phraserel
phrasenode.append(newnonheadwordnode)
return phrasenode


def zullenheadclause(stree: SynTree) -> bool:
if stree.tag == 'node':
cat = gav(stree, 'cat')
Expand Down
42 changes: 25 additions & 17 deletions mwe_query/trymwes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from sastadev.alpinoparsing import parse
from lcat import expandnonheadwords
from sastadev.treebankfunctions import indextransform
from lxml import etree
from canonicalform import generatequeries, expandfull
from .canonicalform import generatequeries, expandfull

debug = False

geenhaankraaien = ('0geen *haan zal naar iets kraaien',
['Daar kraait geen haan naar', 'Hier heeft geen haan naar gekraaid',
'geen haan kraaide daarnaar', 'geen haan kraaide ernaar dat hij niet kwam',
'geen haan kraaide er naar dat hij niet kwam',
'er is geen haan die daar naar kraait', ]
)
geenhaankraaien = (
"0geen *haan zal naar iets kraaien",
[
"Daar kraait geen haan naar",
"Hier heeft geen haan naar gekraaid",
"geen haan kraaide daarnaar",
"geen haan kraaide ernaar dat hij niet kwam",
"geen haan kraaide er naar dat hij niet kwam",
"er is geen haan die daar naar kraait",
],
)


def select(mweutts, utt=None):
if utt is None:
Expand All @@ -20,33 +24,37 @@ def select(mweutts, utt=None):
result = (mweutts[0], [mweutts[1][utt]])
return result


def getparses(utterances):
uttparses = []
for utterance in utterances:
uttparse = parse(utterance)
uttparses.append(uttparse)
return uttparses


def trysomemwes():
mwe, utterances = select(geenhaankraaien)
mwequeries = generatequeries(mwe)
labeledmwequeries = (('MWEQ', mwequeries[0]), ('NMQ', mwequeries[1]), ('MLQ', mwequeries[2]))
labeledmwequeries = (
("MWEQ", mwequeries[0]),
("NMQ", mwequeries[1]),
("MLQ", mwequeries[2]),
)
uttparses = getparses(utterances)
for utterance, uttparse in zip(utterances, uttparses):
print(f'{utterance}:')
print(f"{utterance}:")
expandeduttparse = expandfull(uttparse)
if debug:
etree.dump(expandeduttparse)
for label, mwequery in labeledmwequeries:
results = expandeduttparse.xpath(mwequery)
if debug:
print('Found hits:')
print("Found hits:")
for result in results:
etree.dump(result)
print(f'{label}: {len(results)}')


print(f"{label}: {len(results)}")


if __name__ == '__main__':
trysomemwes()
if __name__ == "__main__":
trysomemwes()
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
# pip-compile
#
Expand Down Expand Up @@ -36,7 +36,7 @@ requests==2.31.0
# via
# alpino-query
# mwe-query (setup.py)
sastadev==0.1.1
sastadev==0.1.4
# via
# auchann
# mwe-query (setup.py)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package_data={"mwe_query": ["py.typed"]},
zip_safe=True,
install_requires=[
'alpino-query>=2.1.8', 'requests', 'BaseXClient', 'sastadev>=0.1.1'
'alpino-query>=2.1.8', 'requests', 'BaseXClient', 'sastadev>=0.1.4'
],
entry_points={
'console_scripts': [
Expand Down

0 comments on commit f3c637d

Please sign in to comment.