Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
material-science-word-embeddings
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schwab
material-science-word-embeddings
Commits
d770fea0
Commit
d770fea0
authored
2 years ago
by
Marie Kl
Browse files
Options
Downloads
Patches
Plain Diff
#20
Created co-occurence matrix - file based per found element in corpus
parent
cb3614d8
No related branches found
No related tags found
No related merge requests found
Pipeline
#20097
passed
2 years ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
get_compounds.py
+14
-1
14 additions, 1 deletion
get_compounds.py
with
14 additions
and
1 deletion
get_compounds.py
+
14
−
1
View file @
d770fea0
...
...
@@ -9,6 +9,7 @@ from tqdm import tqdm
from
collections
import
Counter
from
nltk.tokenize
import
word_tokenize
nltk
.
download
(
'
punkt
'
)
import
csv
class
Document
:
...
...
@@ -67,7 +68,19 @@ if __name__ == '__main__':
# calculate total count of element
result
[
'
total_count
'
]
=
result
[
'
count_per_file
'
].
apply
(
sum
)
result
=
result
.
sort_values
(
'
total_count
'
)
print
(
result
)
#
print(result)
result
.
to_csv
(
"
compounds_found.csv
"
,
index
=
False
)
co_occ
=
result
.
drop
(
'
count_per_file
'
,
axis
=
1
)
co_occ
=
co_occ
.
drop
(
'
total_count
'
,
axis
=
1
)
# create dict for co-occurence matrix
co_occ_dict
=
dict
(
zip
(
co_occ
.
element
,
co_occ
.
file
))
# create co-occurence matrix
values
=
sorted
(
set
(
e
for
v
in
co_occ_dict
.
values
()
for
e
in
v
))
co_occ_matrix
=
{
k
:
[
1
if
value
in
v
else
0
for
value
in
values
]
for
k
,
v
in
co_occ_dict
.
items
()}
with
open
(
'
co_occurence.csv
'
,
'
w
'
)
as
f
:
writer
=
csv
.
writer
(
f
)
writer
.
writerow
(
values
)
for
k
,
v
in
co_occ_matrix
.
items
():
writer
.
writerow
([
k
,
v
])
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