Algorithm for Validation of Reference File with WildcardsWhat is stability in sorting algorithms and why is it important?Is Java “pass-by-reference” or “pass-by-value”?What is the best algorithm for an overridden System.Object.GetHashCode?How do I create a file and write to it in Java?How to avoid Java code in JSP files?Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missingUkkonen's suffix tree algorithm in plain EnglishImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionHow to find time complexity of an algorithmBomb dropping algorithmWhat is the optimal algorithm for the game 2048?
How can I support myself financially as a 17 year old with a loan?
Why did the Apollo 13 crew extend the LM landing gear?
If I readied a spell with the trigger "When I take damage", do I have to make a constitution saving throw to avoid losing Concentration?
Shantae Dance Matching
Why isn't nylon as strong as kevlar?
Which module had more 'comfort' in terms of living space, the Lunar Module or the Command module?
Building a list of products from the elements in another list
As matter approaches a black hole, does it speed up?
How to apply differences on part of a list and keep the rest
Has a commercial or military jet bi-plane ever been manufactured?
Getting a W on your transcript for grad school applications
Can my company stop me from working overtime?
How can I get a job without pushing my family's income into a higher tax bracket?
What was the first instance of a "planet eater" in sci-fi?
Verb "geeitet" in an old scientific text
Make some Prime Squares!
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
Set collection doesn't always enforce uniqueness with the Date datatype? Does the following example seem correct?
Would Hubble Space Telescope improve black hole image observed by EHT if it joined array of telesopes?
Pressure inside an infinite ocean?
How to model the curly cable part of the phone
Why Isn’t SQL More Refactorable?
Send iMessage from Firefox
Have I damaged my car by attempting to reverse with hand/park brake up?
Algorithm for Validation of Reference File with Wildcards
What is stability in sorting algorithms and why is it important?Is Java “pass-by-reference” or “pass-by-value”?What is the best algorithm for an overridden System.Object.GetHashCode?How do I create a file and write to it in Java?How to avoid Java code in JSP files?Easy interview question got harder: given numbers 1..100, find the missing number(s) given exactly k are missingUkkonen's suffix tree algorithm in plain EnglishImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionHow to find time complexity of an algorithmBomb dropping algorithmWhat is the optimal algorithm for the game 2048?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a file like below, which I want to validate for correctness. The file is used as a reference file for processing some data. I match my input data with ColA, ColB and ColC of this file and return OutA of the first match from top. The wildcards '*' match anything. For example, if my input data has X4 Y2 Z3
it will return 13 from the file.
Seq ColA ColB ColC OutA
1 X1 Y1 Z1 10
2 X2 Y2 * 11
3 X3 * Z2 12
4 * Y2 Z3 13
5 * * Z4 14
6 * Y3 Z4 15
7 * * * 16
Now the file can have some entries that are never used or reachable. For example, if I receive X9 Y3 Z4
as my input, it will match with row 5, and will never look at row 6 although row 6 also matches my input. If we exchange the position of row 5 and row 6, it will work as expected. I want to find such unreachable records before my actual process runs.
Any idea on how to find such entries in the file. I am looking for an algorithm. Note that, I have reduced the number of columns and rows in this example. The actual file has around 10 columns and 50 rows.
java algorithm
add a comment |
I have a file like below, which I want to validate for correctness. The file is used as a reference file for processing some data. I match my input data with ColA, ColB and ColC of this file and return OutA of the first match from top. The wildcards '*' match anything. For example, if my input data has X4 Y2 Z3
it will return 13 from the file.
Seq ColA ColB ColC OutA
1 X1 Y1 Z1 10
2 X2 Y2 * 11
3 X3 * Z2 12
4 * Y2 Z3 13
5 * * Z4 14
6 * Y3 Z4 15
7 * * * 16
Now the file can have some entries that are never used or reachable. For example, if I receive X9 Y3 Z4
as my input, it will match with row 5, and will never look at row 6 although row 6 also matches my input. If we exchange the position of row 5 and row 6, it will work as expected. I want to find such unreachable records before my actual process runs.
Any idea on how to find such entries in the file. I am looking for an algorithm. Note that, I have reduced the number of columns and rows in this example. The actual file has around 10 columns and 50 rows.
java algorithm
add a comment |
I have a file like below, which I want to validate for correctness. The file is used as a reference file for processing some data. I match my input data with ColA, ColB and ColC of this file and return OutA of the first match from top. The wildcards '*' match anything. For example, if my input data has X4 Y2 Z3
it will return 13 from the file.
Seq ColA ColB ColC OutA
1 X1 Y1 Z1 10
2 X2 Y2 * 11
3 X3 * Z2 12
4 * Y2 Z3 13
5 * * Z4 14
6 * Y3 Z4 15
7 * * * 16
Now the file can have some entries that are never used or reachable. For example, if I receive X9 Y3 Z4
as my input, it will match with row 5, and will never look at row 6 although row 6 also matches my input. If we exchange the position of row 5 and row 6, it will work as expected. I want to find such unreachable records before my actual process runs.
Any idea on how to find such entries in the file. I am looking for an algorithm. Note that, I have reduced the number of columns and rows in this example. The actual file has around 10 columns and 50 rows.
java algorithm
I have a file like below, which I want to validate for correctness. The file is used as a reference file for processing some data. I match my input data with ColA, ColB and ColC of this file and return OutA of the first match from top. The wildcards '*' match anything. For example, if my input data has X4 Y2 Z3
it will return 13 from the file.
Seq ColA ColB ColC OutA
1 X1 Y1 Z1 10
2 X2 Y2 * 11
3 X3 * Z2 12
4 * Y2 Z3 13
5 * * Z4 14
6 * Y3 Z4 15
7 * * * 16
Now the file can have some entries that are never used or reachable. For example, if I receive X9 Y3 Z4
as my input, it will match with row 5, and will never look at row 6 although row 6 also matches my input. If we exchange the position of row 5 and row 6, it will work as expected. I want to find such unreachable records before my actual process runs.
Any idea on how to find such entries in the file. I am looking for an algorithm. Note that, I have reduced the number of columns and rows in this example. The actual file has around 10 columns and 50 rows.
java algorithm
java algorithm
edited Mar 23 at 0:10
Samik
asked Mar 22 at 22:15
SamikSamik
2,84711621
2,84711621
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Assuming that wildcards match every string (specifically, for each column, there exists a valid symbol that does not appear as a literal), it suffices to check each pair of rows to see whether the first matches a superset of what the second matches. This is the case if and only if, for each column, if the second row has a literal, and then first row has the same literal or a wildcard, and if the second row has a wildcard, then the first row has a wildcard.
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
add a comment |
I would take the approach most web servers use to match request urls to controllers. They take exactly that controller, which fits the resource url best.
/users
/users/userId
If you see a request like /users/2
you would, of course, prefer the second resource controller.
Now back to your problem, the varibale part (you want to match best) relates to the use of *
. If you want to achieve a best-fit, you have to sort all entries, those with the lowest amount of *
at the top, those with the highest at the bottom. (Since you iterate from top to bottom and return upon first match.)
However, for all entries that have the same amount of *
, there can be mutliple fitting rows and there is no way to prevent that. You have to decide, which is one taken.
An simple example demonstrates this:
Seq ColA ColB ColC OutA
20 X3 * Z3 12
21 * Y2 Z3 13
What do you do with X3, Y2, Z3
? The output is not clear and will depend on the sort order. My adwise: Use a stable sorting algorithm to make the output predictable.
For implementation, just create a custom comparator that counts the amount of *
used.
A quick look at List#sort
also shows, that a stable sorting algorithm is already used so you don´t have to worry about it. (Reference)
This implementation is a stable, adaptive, iterative mergesort [...]
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of*
and find out at which row it decreased.
– Samik
Mar 23 at 0:04
On second thought, that is not going to work. if I have two entries like thisX4 * */X5 Y5 *
. They are perfectly valid.
– Samik
Mar 23 at 0:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308474%2falgorithm-for-validation-of-reference-file-with-wildcards%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming that wildcards match every string (specifically, for each column, there exists a valid symbol that does not appear as a literal), it suffices to check each pair of rows to see whether the first matches a superset of what the second matches. This is the case if and only if, for each column, if the second row has a literal, and then first row has the same literal or a wildcard, and if the second row has a wildcard, then the first row has a wildcard.
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
add a comment |
Assuming that wildcards match every string (specifically, for each column, there exists a valid symbol that does not appear as a literal), it suffices to check each pair of rows to see whether the first matches a superset of what the second matches. This is the case if and only if, for each column, if the second row has a literal, and then first row has the same literal or a wildcard, and if the second row has a wildcard, then the first row has a wildcard.
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
add a comment |
Assuming that wildcards match every string (specifically, for each column, there exists a valid symbol that does not appear as a literal), it suffices to check each pair of rows to see whether the first matches a superset of what the second matches. This is the case if and only if, for each column, if the second row has a literal, and then first row has the same literal or a wildcard, and if the second row has a wildcard, then the first row has a wildcard.
Assuming that wildcards match every string (specifically, for each column, there exists a valid symbol that does not appear as a literal), it suffices to check each pair of rows to see whether the first matches a superset of what the second matches. This is the case if and only if, for each column, if the second row has a literal, and then first row has the same literal or a wildcard, and if the second row has a wildcard, then the first row has a wildcard.
answered Mar 23 at 4:32
David EisenstatDavid Eisenstat
38.8k73576
38.8k73576
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
add a comment |
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
Thanks David. So for my 50 row file, I have to do (49+48+...+3+2+1) row compares, which isn't bad. I will try this.
– Samik
Mar 23 at 4:56
add a comment |
I would take the approach most web servers use to match request urls to controllers. They take exactly that controller, which fits the resource url best.
/users
/users/userId
If you see a request like /users/2
you would, of course, prefer the second resource controller.
Now back to your problem, the varibale part (you want to match best) relates to the use of *
. If you want to achieve a best-fit, you have to sort all entries, those with the lowest amount of *
at the top, those with the highest at the bottom. (Since you iterate from top to bottom and return upon first match.)
However, for all entries that have the same amount of *
, there can be mutliple fitting rows and there is no way to prevent that. You have to decide, which is one taken.
An simple example demonstrates this:
Seq ColA ColB ColC OutA
20 X3 * Z3 12
21 * Y2 Z3 13
What do you do with X3, Y2, Z3
? The output is not clear and will depend on the sort order. My adwise: Use a stable sorting algorithm to make the output predictable.
For implementation, just create a custom comparator that counts the amount of *
used.
A quick look at List#sort
also shows, that a stable sorting algorithm is already used so you don´t have to worry about it. (Reference)
This implementation is a stable, adaptive, iterative mergesort [...]
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of*
and find out at which row it decreased.
– Samik
Mar 23 at 0:04
On second thought, that is not going to work. if I have two entries like thisX4 * */X5 Y5 *
. They are perfectly valid.
– Samik
Mar 23 at 0:30
add a comment |
I would take the approach most web servers use to match request urls to controllers. They take exactly that controller, which fits the resource url best.
/users
/users/userId
If you see a request like /users/2
you would, of course, prefer the second resource controller.
Now back to your problem, the varibale part (you want to match best) relates to the use of *
. If you want to achieve a best-fit, you have to sort all entries, those with the lowest amount of *
at the top, those with the highest at the bottom. (Since you iterate from top to bottom and return upon first match.)
However, for all entries that have the same amount of *
, there can be mutliple fitting rows and there is no way to prevent that. You have to decide, which is one taken.
An simple example demonstrates this:
Seq ColA ColB ColC OutA
20 X3 * Z3 12
21 * Y2 Z3 13
What do you do with X3, Y2, Z3
? The output is not clear and will depend on the sort order. My adwise: Use a stable sorting algorithm to make the output predictable.
For implementation, just create a custom comparator that counts the amount of *
used.
A quick look at List#sort
also shows, that a stable sorting algorithm is already used so you don´t have to worry about it. (Reference)
This implementation is a stable, adaptive, iterative mergesort [...]
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of*
and find out at which row it decreased.
– Samik
Mar 23 at 0:04
On second thought, that is not going to work. if I have two entries like thisX4 * */X5 Y5 *
. They are perfectly valid.
– Samik
Mar 23 at 0:30
add a comment |
I would take the approach most web servers use to match request urls to controllers. They take exactly that controller, which fits the resource url best.
/users
/users/userId
If you see a request like /users/2
you would, of course, prefer the second resource controller.
Now back to your problem, the varibale part (you want to match best) relates to the use of *
. If you want to achieve a best-fit, you have to sort all entries, those with the lowest amount of *
at the top, those with the highest at the bottom. (Since you iterate from top to bottom and return upon first match.)
However, for all entries that have the same amount of *
, there can be mutliple fitting rows and there is no way to prevent that. You have to decide, which is one taken.
An simple example demonstrates this:
Seq ColA ColB ColC OutA
20 X3 * Z3 12
21 * Y2 Z3 13
What do you do with X3, Y2, Z3
? The output is not clear and will depend on the sort order. My adwise: Use a stable sorting algorithm to make the output predictable.
For implementation, just create a custom comparator that counts the amount of *
used.
A quick look at List#sort
also shows, that a stable sorting algorithm is already used so you don´t have to worry about it. (Reference)
This implementation is a stable, adaptive, iterative mergesort [...]
I would take the approach most web servers use to match request urls to controllers. They take exactly that controller, which fits the resource url best.
/users
/users/userId
If you see a request like /users/2
you would, of course, prefer the second resource controller.
Now back to your problem, the varibale part (you want to match best) relates to the use of *
. If you want to achieve a best-fit, you have to sort all entries, those with the lowest amount of *
at the top, those with the highest at the bottom. (Since you iterate from top to bottom and return upon first match.)
However, for all entries that have the same amount of *
, there can be mutliple fitting rows and there is no way to prevent that. You have to decide, which is one taken.
An simple example demonstrates this:
Seq ColA ColB ColC OutA
20 X3 * Z3 12
21 * Y2 Z3 13
What do you do with X3, Y2, Z3
? The output is not clear and will depend on the sort order. My adwise: Use a stable sorting algorithm to make the output predictable.
For implementation, just create a custom comparator that counts the amount of *
used.
A quick look at List#sort
also shows, that a stable sorting algorithm is already used so you don´t have to worry about it. (Reference)
This implementation is a stable, adaptive, iterative mergesort [...]
edited Mar 22 at 23:14
answered Mar 22 at 23:07
GlainsGlains
1,270920
1,270920
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of*
and find out at which row it decreased.
– Samik
Mar 23 at 0:04
On second thought, that is not going to work. if I have two entries like thisX4 * */X5 Y5 *
. They are perfectly valid.
– Samik
Mar 23 at 0:30
add a comment |
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of*
and find out at which row it decreased.
– Samik
Mar 23 at 0:04
On second thought, that is not going to work. if I have two entries like thisX4 * */X5 Y5 *
. They are perfectly valid.
– Samik
Mar 23 at 0:30
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of
*
and find out at which row it decreased.– Samik
Mar 23 at 0:04
Thanks Glains. Stable sort looks promising. But since the file is maintained by our end users, I would rather alert them on the wrong sort order instead of sorting it myself. I guess what I was asking can be accomplished by simply counting the number of
*
and find out at which row it decreased.– Samik
Mar 23 at 0:04
On second thought, that is not going to work. if I have two entries like this
X4 * */X5 Y5 *
. They are perfectly valid.– Samik
Mar 23 at 0:30
On second thought, that is not going to work. if I have two entries like this
X4 * */X5 Y5 *
. They are perfectly valid.– Samik
Mar 23 at 0:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308474%2falgorithm-for-validation-of-reference-file-with-wildcards%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown