Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
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
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
Michal Malý
Molstar
Commits
858e6640
Commit
858e6640
authored
7 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
get enumeration values for ucode type fields from mmcif dic
parent
a7119590
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/reader/cif/schema/utils.ts
+43
-27
43 additions, 27 deletions
src/reader/cif/schema/utils.ts
src/script.ts
+2
-2
2 additions, 2 deletions
src/script.ts
with
45 additions
and
29 deletions
src/reader/cif/schema/utils.ts
+
43
−
27
View file @
858e6640
// import dic from './dic'
import
{
Field
,
Category
}
from
'
../schema
'
import
{
Field
/*
, Category
*/
}
from
'
../schema
'
import
*
as
Data
from
'
../data-model
'
const
pooledStr
=
Field
.
pooledStr
()
...
...
@@ -8,7 +8,7 @@ const str = Field.str()
const
int
=
Field
.
int
()
const
float
=
Field
.
float
()
function
getFieldType
(
type
:
string
)
{
export
function
getFieldType
(
type
:
string
)
{
switch
(
type
)
{
case
'
code
'
:
case
'
ucode
'
:
...
...
@@ -71,28 +71,53 @@ interface SafeFrameData {
links
:
SafeFrameLinks
}
function
getCode
(
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
string
|
undefined
{
// get field from given or linked category
function
getField
(
category
:
string
,
field
:
string
,
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
Data
.
Field
|
undefined
{
const
{
categories
,
links
}
=
ctx
const
item_type
=
d
.
categories
[
'
_item_type
'
]
if
(
item_type
)
{
const
code
=
item_type
.
getField
(
'
code
'
)
if
(
code
)
{
return
code
.
str
(
0
)
}
else
{
console
.
log
(
`item_type.code not found for '
${
d
.
header
}
'`
)
}
const
cat
=
d
.
categories
[
category
]
if
(
cat
)
{
return
cat
.
getField
(
field
)
}
else
{
if
(
d
.
header
in
links
)
{
return
get
Code
(
categories
[
links
[
d
.
header
]],
ctx
)
return
get
Field
(
category
,
field
,
categories
[
links
[
d
.
header
]],
ctx
)
}
else
{
console
.
log
(
`no links found for '
${
d
.
header
}
'`
)
// console.log(`no links found for '${d.header}'`)
}
}
}
function
getEnums
(
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
string
[]
|
undefined
{
const
value
=
getField
(
'
_item_enumeration
'
,
'
value
'
,
d
,
ctx
)
if
(
value
)
{
const
enums
:
string
[]
=
[]
for
(
let
i
=
0
;
i
<
value
.
rowCount
;
++
i
)
{
enums
.
push
(
value
.
str
(
i
))
// console.log(value.str(i))
}
return
enums
}
else
{
// console.log(`item_enumeration.value not found for '${d.header}'`)
}
}
function
getCode
(
d
:
Data
.
SafeFrame
,
ctx
:
SafeFrameData
):
string
|
undefined
{
const
code
=
getField
(
'
_item_type
'
,
'
code
'
,
d
,
ctx
)
if
(
code
)
{
let
c
=
code
.
str
(
0
)
if
(
c
===
'
ucode
'
)
{
const
enums
=
getEnums
(
d
,
ctx
)
if
(
enums
)
c
+=
`:
${
enums
.
join
(
'
|
'
)}
`
}
return
c
}
else
{
console
.
log
(
`item_type.code not found for '
${
d
.
header
}
'`
)
}
}
export
function
getSchema
(
dic
:
Data
.
Block
)
{
// todo Block needs to be specialized with safe frames as well
const
schema
:
{
[
category
:
string
]:
Category
.
Schema
}
=
{}
// const schema: { [category: string]: Category.Schema } = {}
const
schema
:
{
[
category
:
string
]:
{
[
k
:
string
]:
string
}
}
=
{}
const
categories
:
SafeFrameCategories
=
{}
const
links
:
SafeFrameLinks
=
{}
...
...
@@ -116,8 +141,9 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special
}
})
Object
.
keys
(
categories
).
forEach
(
categoryName
=>
{
const
d
=
categories
[
categoryName
]
Object
.
keys
(
categories
).
forEach
(
fullName
=>
{
const
d
=
categories
[
fullName
]
const
categoryName
=
d
.
header
.
substring
(
0
,
d
.
header
.
indexOf
(
'
.
'
))
const
itemName
=
d
.
header
.
substring
(
d
.
header
.
indexOf
(
'
.
'
)
+
1
)
let
fields
if
(
categoryName
in
schema
)
{
...
...
@@ -129,7 +155,7 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special
const
code
=
getCode
(
d
,
{
categories
,
links
})
if
(
code
)
{
fields
[
itemName
]
=
getFieldType
(
code
)
fields
[
itemName
]
=
code
//
getFieldType(code)
}
else
{
console
.
log
(
`could not determine code for '
${
d
.
header
}
'`
)
}
...
...
@@ -137,13 +163,3 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special
return
schema
}
// TODO
// support controlled vocabulary as a specialization string type field
// in the example below the string type would be `Y|N`
// _item_type.code ucode
// loop_
// _item_enumeration.value
// _item_enumeration.detail
// Y 'Yes'
// N 'No'
This diff is collapsed.
Click to expand it.
src/script.ts
+
2
−
2
View file @
858e6640
...
...
@@ -151,8 +151,8 @@ async function runDic(input: string | Uint8Array) {
}
const
schema
=
getSchema
(
parsed
.
result
.
blocks
[
0
])
//
console.log(util.inspect(schema, {showHidden: false, depth:
1
}))
console
.
log
(
util
.
inspect
(
Object
.
keys
(
schema
).
length
,
{
showHidden
:
false
,
depth
:
1
}))
console
.
log
(
util
.
inspect
(
schema
,
{
showHidden
:
false
,
depth
:
3
}))
//
console.log(util.inspect(Object.keys(schema).length, {showHidden: false, depth: 1}))
}
export
function
_dic
()
{
...
...
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