Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GPTGrammarParsing
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noah Heuser
GPTGrammarParsing
Commits
50a89b61
Commit
50a89b61
authored
11 months ago
by
Noah Heuser
Browse files
Options
Downloads
Patches
Plain Diff
added ListOfRulesContains
parent
6f9c72d2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ChatGPTParsing/src/auxiliary/ListOfRulesContains.java
+30
-0
30 additions, 0 deletions
ChatGPTParsing/src/auxiliary/ListOfRulesContains.java
ChatGPTParsing/src/type3/Type3GrammarGenerator.java
+9
-5
9 additions, 5 deletions
ChatGPTParsing/src/type3/Type3GrammarGenerator.java
with
39 additions
and
5 deletions
ChatGPTParsing/src/auxiliary/ListOfRulesContains.java
+
30
−
0
View file @
50a89b61
...
...
@@ -2,12 +2,42 @@ package auxiliary;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
public
class
ListOfRulesContains
{
public
static
boolean
contains
(
List
<
Map
<
String
,
List
<
List
<
String
>>>>
container
,
Map
<
String
,
List
<
List
<
String
>>>
contained
)
{
for
(
Map
<
String
,
List
<
List
<
String
>>>
m
:
container
)
{
if
(
equals
(
m
,
contained
))
{
return
true
;
}
}
return
false
;
}
private
static
boolean
equals
(
Map
<
String
,
List
<
List
<
String
>>>
mapA
,
Map
<
String
,
List
<
List
<
String
>>>
mapB
)
{
if
(!
mapA
.
keySet
().
equals
(
mapB
.
keySet
()))
{
return
false
;
}
for
(
Entry
<
String
,
List
<
List
<
String
>>>
entryA
:
mapA
.
entrySet
())
{
if
(!
equals
(
entryA
.
getValue
(),
mapB
.
get
(
entryA
.
getKey
())))
{
return
false
;
}
}
return
true
;
}
private
static
boolean
equals
(
List
<
List
<
String
>>
listA
,
List
<
List
<
String
>>
listB
)
{
if
(
listA
.
size
()
!=
listB
.
size
())
{
return
false
;
}
for
(
int
i
=
0
;
i
<
listA
.
size
();
i
++)
{
if
(!
listA
.
get
(
i
).
equals
(
listB
.
get
(
i
)))
{
return
false
;
}
}
return
true
;
}
}
This diff is collapsed.
Click to expand it.
ChatGPTParsing/src/type3/Type3GrammarGenerator.java
+
9
−
5
View file @
50a89b61
...
...
@@ -9,6 +9,7 @@ import java.util.Random;
import
java.util.Set
;
import
auxiliary.ListOfListContains
;
import
auxiliary.ListOfRulesContains
;
import
co_reachable.CoReachability
;
import
reachable.Reachability
;
...
...
@@ -30,7 +31,7 @@ public class Type3GrammarGenerator {
private
List
<
List
<
String
>>
genConclusios
(
int
alphaSize
,
String
[]
vars
,
int
maxConclusios
,
boolean
start
)
{
List
<
List
<
String
>>
conclusios
=
new
LinkedList
<>();
if
(
start
&&
Math
.
random
()
<=
0.
5
)
{
if
(
start
&&
Math
.
random
()
<=
0.
2
)
{
conclusios
.
add
(
new
LinkedList
<>());
}
int
numOfConclusios
=
random
.
nextInt
(
maxConclusios
)
+
1
;
...
...
@@ -59,7 +60,9 @@ public class Type3GrammarGenerator {
List
<
Map
<
String
,
List
<
List
<
String
>>>>
grammarRuleSets
=
new
LinkedList
<>();
while
(
grammarRuleSets
.
size
()
<
n
)
{
Map
<
String
,
List
<
List
<
String
>>>
rules
=
genType3GrammarRuleSet
(
vars
,
alphaSize
,
maxConclusios
,
s
);
grammarRuleSets
.
add
(
rules
);
if
(!
ListOfRulesContains
.
contains
(
grammarRuleSets
,
rules
))
{
grammarRuleSets
.
add
(
rules
);
}
}
return
grammarRuleSets
;
}
...
...
@@ -69,7 +72,7 @@ public class Type3GrammarGenerator {
List
<
Map
<
String
,
List
<
List
<
String
>>>>
grammarRuleSets
=
new
LinkedList
<>();
while
(
grammarRuleSets
.
size
()
<
n
)
{
Map
<
String
,
List
<
List
<
String
>>>
rules
=
genType3GrammarRuleSet
(
vars
,
alphaSize
,
maxConclusios
,
s
);
if
(!
CoReachability
.
emptyLanguage
(
rules
,
s
))
{
if
(!
CoReachability
.
emptyLanguage
(
rules
,
s
)
&&
!
ListOfRulesContains
.
contains
(
grammarRuleSets
,
rules
)
)
{
grammarRuleSets
.
add
(
rules
);
}
}
...
...
@@ -81,7 +84,8 @@ public class Type3GrammarGenerator {
List
<
Map
<
String
,
List
<
List
<
String
>>>>
grammarRuleSets
=
new
LinkedList
<>();
while
(
grammarRuleSets
.
size
()
<
n
)
{
Map
<
String
,
List
<
List
<
String
>>>
rules
=
genType3GrammarRuleSet
(
vars
,
alphaSize
,
maxConclusios
,
s
);
if
(
CoReachability
.
coReachableSet
(
rules
).
containsAll
(
rules
.
keySet
()))
{
if
(
CoReachability
.
coReachableSet
(
rules
).
containsAll
(
rules
.
keySet
())
&&
!
ListOfRulesContains
.
contains
(
grammarRuleSets
,
rules
))
{
grammarRuleSets
.
add
(
rules
);
}
}
...
...
@@ -100,7 +104,7 @@ public class Type3GrammarGenerator {
boolean
allCoReachable
=
CoReachability
.
coReachableSet
(
rules
).
containsAll
(
rules
.
keySet
());
boolean
allReachable
=
Reachability
.
reachableSet
(
rules
,
s
).
containsAll
(
rules
.
keySet
())
&&
Reachability
.
reachableSet
(
rules
,
s
).
containsAll
(
alphaSet
);
if
(
allCoReachable
&&
allReachable
)
{
if
(
allCoReachable
&&
allReachable
&&
!
ListOfRulesContains
.
contains
(
grammarRuleSets
,
rules
)
)
{
grammarRuleSets
.
add
(
rules
);
}
}
...
...
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