protegeproject / cellfie-plugin

Protégé plugin for creating OWL ontologies from spreadsheets
104 stars 27 forks source link

String manipulation functions #44

Closed nielsthinkiq closed 8 years ago

nielsthinkiq commented 8 years ago

This may be more of a Mapping Master question than a Cellfie question.

Why is there not a concatenation function to join strings? The mm:prepend and mm:append functions seems to only work on selected cells.

For instance, I would like to create a function that created the mm:namespace for each rule based on cell values in the spreadsheet. I would also like to Concatenate "Thing", @B(Asterisk), "", @C(Asterisk)

How do I do that?

Thanks in advance, Niels

BTW: It looks like Markdown is messing with my entry, Asterisks characters are removed.

martinjoconnor commented 8 years ago

You can write something like

Class: @A5(rdf:ID=("Thing", @A5, "", @C*) )

See:

https://github.com/protegeproject/mapping-master/wiki/MappingMasterDSL#processing-cell-content

However, I would suggest you use the rdfs:label instead of the rdf:ID to store meaningful names like this.

See my response to issue https://github.com/protegeproject/cellfie-plugin/issues/45 for the reason.

nielsthinkiq commented 8 years ago

Hi Martin,

Thanks for the quick response.

I did not properly explain what I am trying to do. I am aware of the example that you are referring to.

I need to create a constraint for an equivalent class such that:

Class: @A5 SubclassOf: ABC EquivalentTo: (hasSpecialValue value ("DEF", @B5, "GHI"))

Where ("DEF", @B5, "GHI") represents a concatenation. I am ending up doing the string manipulation in the Excel spreadsheet, but there are two issues with that. 1. It requires a manual step to a file that is automatically generated. 2. The Cellfie importer does not allow functions in the imported spreadsheet, so I have to convert all values to literals in Excel.

I have found no way to concatenate strings outside generating the ID.

Thanks in advance, Niels

martinjoconnor commented 8 years ago

Hi Niels,

Mapping Master effectively only adds a single new clause to the Manchester Syntax: the reference clause. The directives that the language supplies can only be used in this clause. They cannot be used in arbitrary locations.

So you will need to do the following:

Class: @A5 SubclassOf: ABC EquivalentTo: (hasSpecialValue value @B5("DEF", @B5, "GHI"))

Wildcards can be used here, as you would expect, e.g.,

Class: @A SubclassOf: ABC EquivalentTo: (hasSpecialValue value @B("DEF", @B*, "GHI"))

Martin

nielsthinkiq commented 8 years ago

What about

Class: @A SubclassOf: ABC EquivalentTo: (hasSpecialValue value @B("DEF", @B, "GHI", @C))

How do I do that?

martinjoconnor commented 8 years ago

Sorry - don't understand the question. FYI, you can escape asterisks with a backslash.

nielsthinkiq commented 8 years ago

I need to concatenate two strings from column B and C in the spreadsheet.

Class: @A SubclassOf: ABC EquivalentTo: (hasSpecialValue value @B("DEF", @B, "GHI", @C))

to give me "DEFbbbGHIccc" where bbb and ccc represents the values in the cells for a given row in the spreadsheet.

Backslash is great :-), how do I stop the editor from bolding after @?

martinjoconnor commented 8 years ago

The above should work. There is no limit to the amount of reference clauses that can be uses in a concatenation.

Not clear how to escape the at symbol. GitHub is interpreting them as name references.

nielsthinkiq commented 8 years ago

I get an error: Encountered " "(" "( "" at line 3, column 49

It does not seem to like the "(" after @B*, do you have any suggestions?

I can't even get it to work with just @B("ABC", @B)

martinjoconnor commented 8 years ago

Sorry - my mistake.

Try:

Class: @A5 SubclassOf: ABC EquivalentTo: (hasSpecialValue value @B5(rdf:ID=("DEF", @B5, "GHI", @C5)))

I should have more time tomorrow to actually try out the expressions I am suggesting!

nielsthinkiq commented 8 years ago

Just tried it, it works! Thanks!

Where is this documented? I tried https://github.com/protegeproject/mapping-master/wiki/MappingMasterDSL , but it is very sparse in details.

I really would like to find some formatting functions so that i could change "9" to "0009" like I can in Excel with the TEXT(9, "0000") function.

martinjoconnor commented 8 years ago

This section describes rdf:ID and rdfs:label assignment:

https://github.com/protegeproject/mapping-master/wiki/MappingMasterDSL#processing-cell-content

MM has a very small number of pre-canned methods, though we can add new ones on request. I would suggest making a separate feature request issue for suggested methods.

You can also do quite a bit of cell content processing with capturing expressions and the mm:replaceAll function (see section referenced above).

martinjoconnor commented 8 years ago

I have added mm:printf and mm:decimalFormat methods to MM. (They follow the standard Java specifications for String.format and DecimalFormat; see https://docs.oracle.com/javase/tutorial/java/data/numberformat.html.)

You can now say something like:

Individual: Fred Facts: hasSalary @A1(mm:decimalFormat("###,###.00", @A1))

When A1="23000.2" this will render:

Individual: Fred Facts: hasSalary "23,000.20"

And

Class: @A1(mm:printf("A_%s", @A1))

When A1="Car" this will render:

Class: A_Car

Any parameter can be replaced with a reference clause and these functions will work with explicit rdf:ID and rdfs:label assignment too.

Hopefully @johardi can generate a new Cellfie release this week with these updates.

If you are familiar with Maven you can build and install the latest code yourself following the instructions in the READMEs in the following repos:

https://github.com/protegeproject/mapping-master-project https://github.com/protegeproject/cellfie-plugin

There are some (unrelated) failing tests in the integration test project, which you can skip using the instructions provided in the README.

martinjoconnor commented 8 years ago

Note that if only one parameter is supplied the second is assumed to be the enclosing reference location.

So

Individual: Fred Facts: hasSalary @A1(mm:decimalFormat("###,###.00"))

is equivalent to:

Individual: Fred Facts: hasSalary @A1(mm:decimalFormat("###,###.00", @A1))

And

Class: @A1(mm:printf("A_%s"))

is equivalent to:

Class: @A1(mm:printf("A_%s", @A1))

Which is also equivalent to:

Class: @A1(rdf:ID=mm:printf("A_%s", @A1))

nielsthinkiq commented 8 years ago

This is great news.

From: martinjoconnor [mailto:notifications@github.com] Sent: Sunday, January 31, 2016 18:51 To: protegeproject/cellfie-plugin cellfie-plugin@noreply.github.com Cc: Niels Andersen niels@thinkiq.com Subject: Re: [cellfie-plugin] String manipulation functions (#44)

Note that if only one parameter is supplied the second is assumed to be the enclosing reference location.

So

Individual: Fred Facts: hasSalary @A1(mm:decimalFormat("###,###.00"))

is equivalent to:

Individual: Fred Facts: hasSalary @A1(mm:decimalFormat("###,###.00", @A1))

And

Class: @A1(mm:printf("A_%s"))

is equivalent to:

Class: @A1(mm:printf("A_%s", @A1))

Which is also equivalent to:

Class: @A1(rdf:ID=mm:printf("A_%s", @A1))

— Reply to this email directly or view it on GitHubhttps://github.com/protegeproject/cellfie-plugin/issues/44#issuecomment-177724926.

martinjoconnor commented 8 years ago

Hi Josef - did this make it into the Beta 23 release? If so, this should be closed.

johardi commented 8 years ago

Not yet. I will release the new Cellfie this month.

johardi commented 8 years ago

Close #44 via https://github.com/protegeproject/mapping-master/commit/d7486877465c78eb8ced794e8a04f5075d954b76