Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace xpath #22

Merged
merged 16 commits into from
Jun 19, 2024
Merged

Replace xpath #22

merged 16 commits into from
Jun 19, 2024

Conversation

kwkwan
Copy link
Contributor

@kwkwan kwkwan commented May 23, 2024

No description provided.

@kwkwan kwkwan linked an issue May 23, 2024 that may be closed by this pull request
@kwkwan
Copy link
Contributor Author

kwkwan commented May 23, 2024

As parsing xmi file by lutaml/xmi is still NOT fully work at this moment, the commit works are not tested.

Some of the xpath are not converted. Unlike navigating elements by ruby object, xpath can be powerful to go to deep inside in different branches in a tree. The proper way to handle these situation are still investigating.

Copy link
Contributor

@ronaldtse ronaldtse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very happy with the changes so far!

# @param options [Hash] options for parsing
# @return [Lutaml::Uml::Document]
def self.parse(xml, _options = {})
xml_content = File.read(xml).gsub("\t", " ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t need to remove Tabs because we are not doing a compare.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3fc1ece.

# @xmi:type="uml:AssociationClass"]
def serialize_model_classes(package, model)
package.packaged_element.select { |e|
e.type == "uml:Class" || e.type == "uml:AssociationClass"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do “is_a?(Uml::Class)” something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will implement is_type? in Shale::Mapper class to handle these issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t want new methods? Aren’t AssociatedClass etc separate classes?

# @note xpath ./packagedElement[@xmi:type="uml:Enumeration"]
def serialize_model_enums(package)
package.packaged_element
.select { |e| e.type == "uml:Enumeration" }.map do |enum|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, can we use “is_a?”?

# @note xpath
# %(//ownedAttribute[@association]/type[@xmi:idref="#{xmi_id}"])
def fetch_owned_attribute_node(xmi_id)
node = main_model.xpath(%(//ownedAttribute[@association]/type[@xmi:idref="#{xmi_id}"])).first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we replace this later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be replaced later.

definition: lookup_attribute_definition(attribute),
}
end
klass.owned_attribute.select { |attr| attr.type == "uml:Property" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use “is_a?”?

doc_node = main_model.xpath(%(//element[@xmi:idref="#{xmi_id}"]/properties)).first
return unless doc_node

doc_node.attributes[attr_name]&.value
end

def lookup_attribute_definition(node)
xmi_id = node["xmi:id"]
def lookup_attribute_documentation(xmi_id)
doc_node = main_model.xpath(%(//attribute[@xmi:idref="#{xmi_id}"]/documentation)).first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’ll replace this later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be replaced later.

@kwkwan kwkwan merged commit acaa124 into main Jun 19, 2024
2 of 14 checks passed
@ronaldtse ronaldtse deleted the replace-xpath branch June 19, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace xpath in Lutaml::XMI::Parsers::XML
2 participants