mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Support of the .pro file extension for Prolog.
This commit is contained in:
@@ -22,6 +22,9 @@ module Linguist
|
|||||||
if languages.all? { |l| ["ECL", "Prolog"].include?(l) }
|
if languages.all? { |l| ["ECL", "Prolog"].include?(l) }
|
||||||
disambiguate_ecl(data, languages)
|
disambiguate_ecl(data, languages)
|
||||||
end
|
end
|
||||||
|
if languages.all? { |l| ["IDL", "Prolog"].include?(l) }
|
||||||
|
disambiguate_pro(data, languages)
|
||||||
|
end
|
||||||
if languages.all? { |l| ["TypeScript", "XML"].include?(l) }
|
if languages.all? { |l| ["TypeScript", "XML"].include?(l) }
|
||||||
disambiguate_ts(data, languages)
|
disambiguate_ts(data, languages)
|
||||||
end
|
end
|
||||||
@@ -56,6 +59,16 @@ module Linguist
|
|||||||
matches
|
matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.disambiguate_pro(data, languages)
|
||||||
|
matches = []
|
||||||
|
if (data.include?(":-"))
|
||||||
|
matches << Language["Prolog"]
|
||||||
|
else
|
||||||
|
matches << Language["IDL"]
|
||||||
|
end
|
||||||
|
matches
|
||||||
|
end
|
||||||
|
|
||||||
def self.disambiguate_ts(data, languages)
|
def self.disambiguate_ts(data, languages)
|
||||||
matches = []
|
matches = []
|
||||||
if (data.include?("</translation>"))
|
if (data.include?("</translation>"))
|
||||||
|
|||||||
@@ -1325,6 +1325,7 @@ Prolog:
|
|||||||
extensions:
|
extensions:
|
||||||
- .ecl
|
- .ecl
|
||||||
- .pl
|
- .pl
|
||||||
|
- .pro
|
||||||
|
|
||||||
Protocol Buffer:
|
Protocol Buffer:
|
||||||
type: markup
|
type: markup
|
||||||
|
|||||||
68
samples/Prolog/logic-problem.pro
Normal file
68
samples/Prolog/logic-problem.pro
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* Question 1.1
|
||||||
|
* combiner(+Buddies, -Pairs)
|
||||||
|
*/
|
||||||
|
combiner([], []).
|
||||||
|
combiner([First|Buddies], Pairs):-
|
||||||
|
make_pairs(First, Buddies, Pairs1),
|
||||||
|
combiner(Buddies, Pairs2),
|
||||||
|
concat(Pairs1, Pairs2, Pairs).
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make_pairs(+Buddy, +Buddies, -Pairs)
|
||||||
|
*/
|
||||||
|
make_pairs(Buddy, [], []).
|
||||||
|
make_pairs(Buddy, [First|Buddies], [(Buddy, First)|Pairs]):-
|
||||||
|
make_pairs(Buddy, Buddies, Pairs).
|
||||||
|
|
||||||
|
/**
|
||||||
|
* concat(+X, +Y, ?T)
|
||||||
|
*/
|
||||||
|
concat([], Y, Y).
|
||||||
|
concat([P|R], Y, [P|T]):-
|
||||||
|
concat(R, Y, T).
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Question 1.2
|
||||||
|
* extraire(+AllPossiblePairs, +NbPairs, -Tp, -RemainingPairs)
|
||||||
|
*/
|
||||||
|
extraire(AllPossiblePairs, 0, [], AllPossiblePairs).
|
||||||
|
extraire([PossiblePair|AllPossiblePairs], NbPairs, [PossiblePair|Tp], NewRemainingPairs):-
|
||||||
|
NbPairs > 0,
|
||||||
|
NewNbPairs is NbPairs - 1,
|
||||||
|
extraire(AllPossiblePairs, NewNbPairs, Tp, RemainingPairs),
|
||||||
|
not(pair_in_array(PossiblePair, Tp)),
|
||||||
|
delete_pair(RemainingPairs, PossiblePair, NewRemainingPairs).
|
||||||
|
extraire([PossiblePair|AllPossiblePairs], NbPairs, Tp, [PossiblePair|RemainingPairs]):-
|
||||||
|
NbPairs > 0,
|
||||||
|
extraire(AllPossiblePairs, NbPairs, Tp, RemainingPairs),
|
||||||
|
pair_in_array(PossiblePair, Tp).
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete_pair(+Pairs, +Pair, -PairsWithoutPair)
|
||||||
|
*/
|
||||||
|
delete_pair([], _, []).
|
||||||
|
delete_pair([Pair|Pairs], Pair, Pairs):-!.
|
||||||
|
delete_pair([FirstPair|Pairs], Pair, [FirstPair|PairsWithoutPair]):-
|
||||||
|
delete_pair(Pairs, Pair, PairsWithoutPair).
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pair_in_array(+Pair, +Pairs)
|
||||||
|
*/
|
||||||
|
pair_in_array((A, B), [(C, D)|Pairs]):-
|
||||||
|
(A == C ; B == D ; A == D ; B == C),
|
||||||
|
!.
|
||||||
|
pair_in_array(Pair, [FirstPair|Pairs]):-
|
||||||
|
pair_in_array(Pair, Pairs).
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Question 1.3
|
||||||
|
* les_tps(+Buddies, -Tps)
|
||||||
|
*/
|
||||||
|
les_tps(Buddies, Tps):-
|
||||||
|
combiner(Buddies, PossiblePairs),
|
||||||
|
length(Buddies, NbBuddies),
|
||||||
|
NbPairs is integer(NbBuddies / 2),
|
||||||
|
findall(Tp, extraire(PossiblePairs, NbPairs, Tp, _), Tps).
|
||||||
@@ -63,6 +63,18 @@ class TestHeuristcs < Test::Unit::TestCase
|
|||||||
assert_equal Language["ECL"], results.first
|
assert_equal Language["ECL"], results.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_pro_prolog_by_heuristics
|
||||||
|
languages = ["IDL", "Prolog"]
|
||||||
|
results = Heuristics.disambiguate_pro(fixture("Prolog/logic-problem.pro"), languages)
|
||||||
|
assert_equal Language["Prolog"], results.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pro_idl_by_heuristics
|
||||||
|
languages = ["IDL", "Prolog"]
|
||||||
|
results = Heuristics.disambiguate_pro(fixture("IDL/mg_acosh.pro"), languages)
|
||||||
|
assert_equal Language["IDL"], results.first
|
||||||
|
end
|
||||||
|
|
||||||
def test_ts_typescript_by_heuristics
|
def test_ts_typescript_by_heuristics
|
||||||
languages = ["TypeScript", "XML"]
|
languages = ["TypeScript", "XML"]
|
||||||
results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages)
|
results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages)
|
||||||
|
|||||||
Reference in New Issue
Block a user