MCPcopy Create free account
hub / github.com/Effect-TS/effect / groupSimilarity

Function groupSimilarity

packages/tools/api-diff/src/Diff.ts:110–155  ·  view source on GitHub ↗
(
  base: ApiGroup,
  head: ApiGroup
)

Source from the content-addressed store, hash-verified

108const groupName = (group: ApiGroup): string => group.path.at(-1) ?? ""
109
110const groupSimilarity = (
111 base: ApiGroup,
112 head: ApiGroup
113): number => {
114 const facets = base.entities.flatMap((baseEntity) => {
115 const headEntity = head.entities.find((candidate) => candidate.bucket === baseEntity.bucket)
116 return headEntity === undefined ? [] : [{ base: baseEntity, head: headEntity }]
117 })
118 if (facets.length === 0) {
119 return 0
120 }
121 const sameKind = facets.filter(({ base, head }) => base.declarationKind === head.declarationKind).length /
122 facets.length
123 const sameFingerprint = facets.filter(({ base, head }) => base.fingerprint === head.fingerprint).length /
124 facets.length
125 const structure = facets.reduce(
126 (total, { base, head }) => total + setSimilarity(entityFeatures(base), entityFeatures(head)),
127 0
128 ) / facets.length
129 const documentation = facets.reduce(
130 (total, { base, head }) => total + setSimilarity(documentationTokens(base), documentationTokens(head)),
131 0
132 ) / facets.length
133 const sameCategory = facets.some(({ base, head }) =>
134 base.documentation.category !== undefined &&
135 base.documentation.category === head.documentation.category
136 )
137 const headModuleName = head.module.split("/").at(-1)?.toLowerCase()
138 const mentionsHeadModule = headModuleName !== undefined &&
139 facets.some(({ base }) => documentationTokens(base).has(headModuleName))
140 const moduleScore = base.module === head.module ? 0.25 : 0
141 const packageScore = base.entities[0]!.packageName === head.entities[0]!.packageName ? 0.05 : 0
142 return Math.min(
143 0.99,
144 0.2 * nameSimilarity(groupName(base), groupName(head)) +
145 (groupName(base) === groupName(head) ? 0.15 : 0) +
146 moduleScore +
147 packageScore +
148 0.4 * sameFingerprint +
149 0.15 * sameKind +
150 0.15 * structure +
151 0.025 * documentation +
152 (sameCategory ? 0.05 : 0) +
153 (mentionsHeadModule ? 0.075 : 0)
154 )
155}
156
157const changeId = (
158 classification: ChangeClassification,

Callers 1

diffSnapshotsFunction · 0.85

Calls 11

setSimilarityFunction · 0.85
entityFeaturesFunction · 0.85
documentationTokensFunction · 0.85
nameSimilarityFunction · 0.85
groupNameFunction · 0.85
filterMethod · 0.80
someMethod · 0.80
atMethod · 0.65
findMethod · 0.45
splitMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected