diff --git a/src/Type_Definitions/Common_Common.js b/src/Type_Definitions/Common_Common.js index e0f9959..3471cd5 100644 --- a/src/Type_Definitions/Common_Common.js +++ b/src/Type_Definitions/Common_Common.js @@ -13,7 +13,6 @@ const commonDefs = gql` checkSimilarPosts( post1Id: String post2Id: String - algo: similarImageAlgorithm ): checkSimilarPostsDetails! } @@ -21,12 +20,6 @@ const commonDefs = gql` postIds: [String] } - enum similarImageAlgorithm { - HAMMING - LEVENSHTEIN - ALL - } - type checkSimilarPostsDetails { isSimilar: Boolean post1Imageurl: String diff --git a/src/Type_Definitions/Post_Post.js b/src/Type_Definitions/Post_Post.js index 8800460..3d5c80c 100644 --- a/src/Type_Definitions/Post_Post.js +++ b/src/Type_Definitions/Post_Post.js @@ -32,16 +32,9 @@ const postDefs = gql` data: SimilarPostsInput! limit: Int after: String - algo: similarImageAlgorithm ): PostPagination! } - enum similarImageAlgorithm { - HAMMING - LEVENSHTEIN - ALL - } - type PostPagination { edges: [PostEdge!]! pageInfo: PageInfo! diff --git a/src/constants.js b/src/constants.js index c908dea..c3d2ee8 100644 --- a/src/constants.js +++ b/src/constants.js @@ -6,12 +6,6 @@ export const VOTE_COMMENT_ACTION = { CANCEL: 'CANCEL', }; -export const SIMILAR_IMAGE_ALGORITHM = { - HAMMING: 'HAMMING', - LEVENSHTEIN: 'LEVENSHTEIN', - ALL: 'ALL', -}; - export const DEFAULT_DEFINED_SKILL_LIST = [ 'Abstract', 'Animal', diff --git a/src/resolvers/Common/compareImages.js b/src/resolvers/Common/compareImages.js index f8b6c20..8e35b3c 100644 --- a/src/resolvers/Common/compareImages.js +++ b/src/resolvers/Common/compareImages.js @@ -1,43 +1,14 @@ -import Jimp from 'jimp'; -import leven from 'leven'; -import { SIMILAR_IMAGE_ALGORITHM } from '../../constants.js'; - -export function compareImages( - image1hash, - image2hash, - algo = SIMILAR_IMAGE_ALGORITHM.ALL, -) { +export function compareImages(image1hash, image2hash) { // Perceived distance const hammingDistance = findHammingDistance(image1hash, image2hash); - const levenDistance = leven(image1hash, image2hash); console.log(`compareImages: hamming distance: ${hammingDistance.toFixed(3)}`); - console.log(`compareImages: leven distance: ${levenDistance.toFixed(3)}`); - switch (algo) { - case SIMILAR_IMAGE_ALGORITHM.HAMMING: - if (hammingDistance <= 10) { - console.log('compareImages: Images match!'); - return true; - } - console.log('compareImages: Images do NOT match!'); - return false; - case SIMILAR_IMAGE_ALGORITHM.LEVENSHTEIN: - if (levenDistance <= 12) { - console.log('compareImages: Images match!'); - return true; - } - console.log('compareImages: Images do NOT match!'); - return false; - case SIMILAR_IMAGE_ALGORITHM.ALL: - if (hammingDistance <= 10 || levenDistance <= 12) { - console.log('compareImages: Images match!'); - return true; - } - console.log('compareImages: Images do NOT match!'); - return false; - default: - throw Error('Similar Image Algorithm is not specified'); + if (hammingDistance <= 10) { + console.log('compareImages: Images match!'); + return true; } + console.log('compareImages: Images do NOT match!'); + return false; } const findHammingDistance = (str1 = '', str2 = '') => { diff --git a/src/resolvers/Mutation/utility.js b/src/resolvers/Mutation/utility.js index de5fd98..555f16a 100644 --- a/src/resolvers/Mutation/utility.js +++ b/src/resolvers/Mutation/utility.js @@ -56,12 +56,12 @@ const utilityMutation = { /** * * @param {*} parent - * @param {{post1Id: string, post2Id: string, algo: string}} args + * @param {{post1Id: string, post2Id: string}} args * @param {*} info * @returns */ checkSimilarPosts: async (parent, args, info) => { - const { post1Id, post2Id, algo } = args; + const { post1Id, post2Id } = args; const allPosts = await prisma.post.findMany({ where: { id: { @@ -79,7 +79,7 @@ const utilityMutation = { const hash1 = images[0].hash; const hash2 = images[1].hash; - const result = compareImages(hash1, hash2, algo); + const result = compareImages(hash1, hash2); return { isSimilar: result, post1Imageurl: images[0].url, diff --git a/src/resolvers/Query/POST.js b/src/resolvers/Query/POST.js index e940f71..b9635c1 100644 --- a/src/resolvers/Query/POST.js +++ b/src/resolvers/Query/POST.js @@ -337,12 +337,12 @@ const postQuery = { /** * @param {*} parent - * @param {{data: {postId: string}, limit: number, after: string, algo: string}} args + * @param {{data: {postId: string}, limit: number, after: string}} args * @param {*} info * @returns */ similarPosts: async (parent, args, info) => { - const { after, limit = DEFAULT_LIMIT, algo } = args; + const { after, limit = DEFAULT_LIMIT } = args; const { postId } = args.data ? args.data : {}; if (!postId) { @@ -393,7 +393,7 @@ const postQuery = { console.log('Init Stage wit referenceImage URL: ', referenceImage.url); const initImages = initPosts.map((each) => each.image); const isSimilarImageMap = initImages.map((each) => - compareImages(referenceImage.hash, each.hash, algo), + compareImages(referenceImage.hash, each.hash), ); for (const imgIndex in initImages) { if (isSimilarImageMap[imgIndex]) { @@ -436,7 +436,7 @@ const postQuery = { const nextImages = nextPosts.map((each) => each.image); const isSimilarImageMap = nextImages.map((each) => - compareImages(referenceImage.hash, each.hash, algo), + compareImages(referenceImage.hash, each.hash), ); for (const imgIndex in nextImages) { if (result.length === limit) {