Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Macao Legacy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MACAO
Macao Legacy
Commits
49950a5e
Commit
49950a5e
authored
6 months ago
by
David Rouquet
Browse files
Options
Downloads
Patches
Plain Diff
use markitdown instead of pandoc and prepare HTML before MD conversion
parent
e5030174
No related branches found
No related tags found
1 merge request
!4
Main
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tetras_extraction/script/requirements.txt
+3
-1
3 additions, 1 deletion
tetras_extraction/script/requirements.txt
tetras_extraction/script/src/transform.py
+28
-6
28 additions, 6 deletions
tetras_extraction/script/src/transform.py
with
31 additions
and
7 deletions
tetras_extraction/script/requirements.txt
+
3
−
1
View file @
49950a5e
...
@@ -10,4 +10,6 @@ types-beautifulsoup4==4.12.0.20240511
...
@@ -10,4 +10,6 @@ types-beautifulsoup4==4.12.0.20240511
types-html5lib==1.1.11.20240228
types-html5lib==1.1.11.20240228
types-lxml==2024.4.14
types-lxml==2024.4.14
typing_extensions==4.12.1
typing_extensions==4.12.1
pandoc
#pandoc
#python_on_whales
markitdown
This diff is collapsed.
Click to expand it.
tetras_extraction/script/src/transform.py
+
28
−
6
View file @
49950a5e
from
rdflib
import
OWL
,
RDF
,
Graph
,
Literal
from
rdflib
import
OWL
,
RDF
,
Graph
,
Literal
from
lxml
import
html
from
lxml
import
html
import
pandoc
#import pandoc
from
markitdown
import
MarkItDown
import
tempfile
import
re
from
common
import
*
from
common
import
*
...
@@ -30,6 +33,12 @@ def construct_while(g: Graph, query: str):
...
@@ -30,6 +33,12 @@ def construct_while(g: Graph, query: str):
while
construct
(
g
,
query
)
>
0
:
while
construct
(
g
,
query
)
>
0
:
pass
pass
def
prepareHTMLforMD
(
str
):
audio
=
"

"
#regexJS = re.compile(r'<script type="text/javascript">(.*)</script>')
regexAV
=
re
.
compile
(
r
"
.*?PF_clipAV\(
'
.*?
'
,
'
(.*?)
'
,.*
"
)
str
=
regexAV
.
sub
(
audio
,
str
)
return
(
str
)
def
transform_html
(
graph
:
Graph
):
def
transform_html
(
graph
:
Graph
):
html_properties
=
[
'
commentaireInfo
'
,
'
commentaireSucces
'
,
'
commentaireSugg
'
,
'
html
'
,
'
description
'
]
html_properties
=
[
'
commentaireInfo
'
,
'
commentaireSucces
'
,
'
commentaireSugg
'
,
'
html
'
,
'
description
'
]
...
@@ -53,19 +62,32 @@ def transform_html(graph: Graph):
...
@@ -53,19 +62,32 @@ def transform_html(graph: Graph):
pass
pass
"""
"""
# Process all html content through Pandoc
# Process all html content through Pandoc -> We use Markitdown instead at the moment
#for prop in html_properties:
# for t in graph.triples((None, NS[prop], None)) :
# desc_str = t[2]
# desc_doc = pandoc.read(desc_str, format="html")
# desc_md = pandoc.write(desc_doc, format="markdown")
# l = list(t)
# l[2] = Literal(desc_md)
# l[1] = NS[prop+'_md']
# graph.add(tuple(l))
# Process all html content through Markitdown
for
prop
in
html_properties
:
for
prop
in
html_properties
:
for
t
in
graph
.
triples
((
None
,
NS
[
prop
],
None
))
:
for
t
in
graph
.
triples
((
None
,
NS
[
prop
],
None
))
:
desc_str
=
t
[
2
]
desc_str
=
prepareHTMLforMD
(
t
[
2
])
desc_doc
=
pandoc
.
read
(
desc_str
,
format
=
"
html
"
)
tmp
=
tempfile
.
NamedTemporaryFile
(
suffix
=
"
.html
"
)
desc_md
=
pandoc
.
write
(
desc_doc
,
format
=
"
markdown
"
)
with
open
(
tmp
.
name
,
'
w
'
)
as
f
:
f
.
write
(
desc_str
)
mid
=
MarkItDown
()
desc_md
=
mid
.
convert
(
tmp
.
name
).
text_content
l
=
list
(
t
)
l
=
list
(
t
)
l
[
2
]
=
Literal
(
desc_md
)
l
[
2
]
=
Literal
(
desc_md
)
l
[
1
]
=
NS
[
prop
+
'
_md
'
]
l
[
1
]
=
NS
[
prop
+
'
_md
'
]
graph
.
add
(
tuple
(
l
))
graph
.
add
(
tuple
(
l
))
def
main
():
def
main
():
# Load graph
# Load graph
graph
=
Graph
()
graph
=
Graph
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment