-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Element classification inference is no longer rewritten by a simpler …
…element later in the document. More tests and bit of reorganization & commenting.
- Loading branch information
1 parent
54d1dc8
commit 0e95822
Showing
36 changed files
with
218 additions
and
76 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
repository/XML-MA-Generator.package/XOGElementClassification.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I unify the information form valueType and type classification. |
8 changes: 8 additions & 0 deletions
8
...tory/XML-MA-Generator.package/XOGElementClassification.class/instance/attributesOf.in..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
retrieving | ||
attributesOf: anElementPath in: aMapping | ||
^ aMapping associations | ||
select: [ :pair | | ||
| path | | ||
path := pair key. | ||
(path beginsWith: anElementPath) | ||
and: [ path size = (anElementPath size + 1) and: [ path last includes: $@ ] ] ] |
8 changes: 8 additions & 0 deletions
8
...sitory/XML-MA-Generator.package/XOGElementClassification.class/instance/childrenOf.in..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
retrieving | ||
childrenOf: anElementPath in: aMapping | ||
^ aMapping associations | ||
select: [ :pair | | ||
| path | | ||
path := pair key. | ||
(path beginsWith: anElementPath) | ||
and: [ path size = (anElementPath size + 1) and: [ (path last includes: $@) not ] ] ] |
36 changes: 36 additions & 0 deletions
36
...r.package/XOGElementClassification.class/instance/classifyElement.withTypes.andValues..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
retrieving | ||
classifyElement: anElementPath withTypes: types andValues: valueTypes | ||
| type classification | | ||
type := types at: anElementPath. | ||
type isList | type isInlined | ||
ifTrue: [ ^ nil ]. | ||
classification := OrderedCollection new. | ||
(self attributesOf: anElementPath in: valueTypes) | ||
do: [ :pair | | ||
classification | ||
add: (pair key last copyUpTo: $[) -> (Array with: #attribute with: pair value) ]. | ||
(self childrenOf: anElementPath in: valueTypes) | ||
do: [ :pair | | ||
| childPath childType childName | | ||
childPath := pair key. | ||
childName := childPath last. | ||
childType := types at: childPath. | ||
childType isList | ||
ifTrue: [ classification add: childName -> (Array with: #list with: childType childName) ]. | ||
childType isInlined | ||
ifTrue: [ | childAttrs | | ||
childAttrs := self attributesOf: childPath in: valueTypes. | ||
childAttrs | ||
ifEmpty: [ classification | ||
add: childName -> (Array with: #inlinedElement with: (valueTypes at: childPath)) ] | ||
ifNotEmpty: [ classification | ||
add: | ||
childName | ||
-> | ||
(Array | ||
with: #inlinedAttribute | ||
with: (childAttrs first key last copyUpTo: $[) | ||
with: (valueTypes at: childAttrs first key)) ] ]. | ||
childType isComplex | ||
ifTrue: [ classification add: childName -> #(complex) ] ]. | ||
^ classification |
10 changes: 10 additions & 0 deletions
10
...-MA-Generator.package/XOGElementClassification.class/instance/classifyTypes.andValues..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
retrieving | ||
classifyTypes: aTypesDictionary andValues: aValueTypesDictionary | ||
| types valueTypes | | ||
types := self convertToPaths: aTypesDictionary. | ||
valueTypes := self convertToPaths: aValueTypesDictionary. | ||
^ self | ||
convertFromPaths: | ||
(types keys | ||
collect: [ :path | path -> (self classifyElement: path withTypes: types andValues: valueTypes) ]) | ||
asOrderedDictionary |
4 changes: 4 additions & 0 deletions
4
...ory/XML-MA-Generator.package/XOGElementClassification.class/instance/convertFromPaths..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
utility | ||
convertFromPaths: aDictionary | ||
^ (aDictionary associations | ||
collect: [ :pair | ('/' , (pair key joinUsing: $/)) -> pair value ]) asOrderedDictionary |
5 changes: 5 additions & 0 deletions
5
...itory/XML-MA-Generator.package/XOGElementClassification.class/instance/convertToPaths..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
utility | ||
convertToPaths: aDictionary | ||
^ (aDictionary associations | ||
collect: [ :pair | (pair key allButFirst splitOn: $/) asArray -> pair value ]) | ||
asOrderedDictionary |
11 changes: 11 additions & 0 deletions
11
repository/XML-MA-Generator.package/XOGElementClassification.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commentStamp" : "PeterUhnak 7/16/2017 23:27", | ||
"super" : "Object", | ||
"category" : "XML-MA-Generator-Inference", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "XOGElementClassification", | ||
"type" : "normal" | ||
} |
Empty file.
16 changes: 16 additions & 0 deletions
16
repository/XML-MA-Generator.package/XOGElementClassificationTest.class/instance/setUp.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
running | ||
setUp | ||
super setUp. | ||
classification := XOGElementClassification new. | ||
types := {#(complex) -> XOGTypeClassification complex. | ||
#(complex list) -> (XOGTypeClassification list childName: 'item'). | ||
#(complex list item) -> XOGTypeClassification complex. | ||
#(complex inlinedAttr) -> XOGTypeClassification inlined. | ||
#(complex inlinedElement) -> XOGTypeClassification inlined} asOrderedDictionary. | ||
valueTypes := {#(complex) -> #Empty. | ||
#(complex inlinedAttr) -> #Empty. | ||
#(complex inlinedAttr 'value[@value]') -> #String. | ||
#(complex inlinedElement) -> #String. | ||
#(complex list) -> #Empty. | ||
#(complex list item) -> #Empty. | ||
#(complex list item 'name[@name]') -> #String} asOrderedDictionary |
17 changes: 17 additions & 0 deletions
17
...y/XML-MA-Generator.package/XOGElementClassificationTest.class/instance/testClassifyAll.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tests | ||
testClassifyAll | ||
self | ||
assert: | ||
(classification | ||
classifyTypes: (classification convertFromPaths: types) | ||
andValues: (classification convertFromPaths: valueTypes)) | ||
equals: | ||
{'/complex' | ||
-> | ||
{'inlinedAttr' -> #(inlinedAttribute 'value' String). | ||
'inlinedElement' -> #(inlinedElement String). | ||
'list' -> #(list item)} asOrderedCollection. | ||
'/complex/list' -> nil. | ||
'/complex/list/item' -> {'name' -> #(attribute String)} asOrderedCollection. | ||
'/complex/inlinedAttr' -> nil. | ||
'/complex/inlinedElement' -> nil} asOrderedDictionary |
8 changes: 8 additions & 0 deletions
8
...nerator.package/XOGElementClassificationTest.class/instance/testClassifyElementComplex.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tests | ||
testClassifyElementComplex | ||
self | ||
assert: (classification classifyElement: #(complex) withTypes: types andValues: valueTypes) asArray | ||
equals: | ||
{#inlinedAttr -> #(inlinedAttribute 'value' String). | ||
#inlinedElement -> #(inlinedElement String). | ||
#list -> #(list item)} |
9 changes: 9 additions & 0 deletions
9
...tor.package/XOGElementClassificationTest.class/instance/testClassifyElementEasyComplex.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests | ||
testClassifyElementEasyComplex | ||
self | ||
assert: | ||
(classification | ||
classifyElement: #(complex list item) | ||
withTypes: types | ||
andValues: valueTypes) asArray | ||
equals: {'name' -> #(attribute String)} |
5 changes: 5 additions & 0 deletions
5
...nerator.package/XOGElementClassificationTest.class/instance/testClassifyElementInlined.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tests - classification | ||
testClassifyElementInlined | ||
self | ||
assert: (classification classifyElement: #(complex inlinedElement) withTypes: types andValues: valueTypes) | ||
equals: nil |
5 changes: 5 additions & 0 deletions
5
...-Generator.package/XOGElementClassificationTest.class/instance/testClassifyElementList.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tests - classification | ||
testClassifyElementList | ||
self | ||
assert: (classification classifyElement: #(complex list) withTypes: types andValues: valueTypes) | ||
equals: nil |
11 changes: 11 additions & 0 deletions
11
...-MA-Generator.package/XOGElementClassificationTest.class/instance/testConvertFromPaths.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
tests - utility | ||
testConvertFromPaths | ||
self | ||
assert: | ||
(classification | ||
convertFromPaths: | ||
{#(a) -> nil. | ||
#(a b) -> nil} asOrderedDictionary) | ||
equals: | ||
{'/a' -> nil. | ||
'/a/b' -> nil} asOrderedDictionary |
11 changes: 11 additions & 0 deletions
11
...ML-MA-Generator.package/XOGElementClassificationTest.class/instance/testConvertToPaths.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
tests - utility | ||
testConvertToPaths | ||
self | ||
assert: | ||
(classification | ||
convertToPaths: | ||
{'/a' -> nil. | ||
'/a/b' -> nil} asOrderedDictionary) | ||
equals: | ||
{#(a) -> nil. | ||
#(a b) -> nil} asOrderedDictionary |
5 changes: 5 additions & 0 deletions
5
...A-Generator.package/XOGElementClassificationTest.class/instance/testRetrieveAttributes.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tests - retrieving | ||
testRetrieveAttributes | ||
self | ||
assert: (classification attributesOf: #(complex list item) in: valueTypes) | ||
equals: {#(complex list item 'name[@name]') -> #String} |
5 changes: 5 additions & 0 deletions
5
...-MA-Generator.package/XOGElementClassificationTest.class/instance/testRetrieveChildren.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tests - retrieving | ||
testRetrieveChildren | ||
| children | | ||
children := classification childrenOf: #(complex list) in: valueTypes. | ||
self assert: children equals: {#(complex list item) -> #Empty} |
18 changes: 18 additions & 0 deletions
18
repository/XML-MA-Generator.package/XOGElementClassificationTest.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"commentStamp" : "", | ||
"super" : "XOGTestCase", | ||
"category" : "XML-MA-Generator-Tests", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"generator", | ||
"classification", | ||
"dom", | ||
"element", | ||
"types", | ||
"valueTypes" | ||
], | ||
"name" : "XOGElementClassificationTest", | ||
"type" : "normal" | ||
} |
6 changes: 5 additions & 1 deletion
6
repository/XML-MA-Generator.package/XOGStructureGenerator.class/instance/processDocument..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
xml processing | ||
processDocument: aDocument | ||
self typeHierarchy: (XOGTypeClassification new hierarchyFor: aDocument). | ||
| types valueTypes classification | | ||
types := XOGTypeClassification new classificationFor: aDocument. | ||
valueTypes := XOGValueTypeInference new inferDocument: aDocument. | ||
classification := XOGElementClassification new classifyTypes: types andValues: valueTypes. | ||
self typeHierarchy: classification. | ||
aDocument allElements do: [ :each | self processElement: each ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I represent an element whose type hasn't been determined yet. |
2 changes: 1 addition & 1 deletion
2
repository/XML-MA-Generator.package/XOGTypeAny.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
repository/XML-MA-Generator.package/XOGTypeClassification.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
...ckage/XOGTypeClassification.class/instance/attributesForElement.basedOn.andValueTypes..st
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
repository/XML-MA-Generator.package/XOGTypeClassification.class/instance/hierarchyFor..st
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
repository/XML-MA-Generator.package/XOGTypeClassification.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
...sitory/XML-MA-Generator.package/XOGTypeClassificationTest.class/instance/testHierarchy.st
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I represent a complex element that has attributes and various subelements. |
2 changes: 1 addition & 1 deletion
2
repository/XML-MA-Generator.package/XOGTypeComplex.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I represent an element that has only string value and will be inlined as an attribute of the partent #complex type. |
2 changes: 1 addition & 1 deletion
2
repository/XML-MA-Generator.package/XOGTypeInlined.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I represent a XML element that has no attributes and all its children have the same name (=childName). |
2 changes: 1 addition & 1 deletion
2
repository/XML-MA-Generator.package/XOGTypeList.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
repository/XML-MA-Generator.package/XOGValueTypeInference.class/instance/mergeTypes..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
as yet unclassified | ||
mergeTypes: aCollection | ||
(aCollection includes: #String) | ||
ifTrue: [ ^ #String ]. | ||
(aCollection includes: #Float) | ||
ifTrue: [ ^ #Float ]. | ||
(aCollection allSatisfy: [ :each | each = aCollection first ]) | ||
ifFalse: [ self error: 'Unforeseen error (obviously)' ]. | ||
^ aCollection anyOne | ||
| types | | ||
types := aCollection removeDuplicates. | ||
types removeAllSuchThat: [ :each | each = #Empty ]. | ||
types ifEmpty: [ ^ #Empty ]. | ||
types size > 1 | ||
ifTrue: [ self error: 'Unforeseen error (obviously)' ]. | ||
^ types first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters